mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
42 lines
894 B
Ruby
42 lines
894 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Users
|
|
module Digests
|
|
class ChartImageGenerator
|
|
def initialize(digest, distance_unit: 'km')
|
|
@digest = digest
|
|
@distance_unit = distance_unit
|
|
end
|
|
|
|
def call
|
|
html = render_chart_html
|
|
generate_image(html)
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :digest, :distance_unit
|
|
|
|
def render_chart_html
|
|
ApplicationController.render(
|
|
template: 'user/digests/chart',
|
|
layout: false,
|
|
assigns: {
|
|
monthly_distances: digest.monthly_distances,
|
|
distance_unit: distance_unit
|
|
}
|
|
)
|
|
end
|
|
|
|
def generate_image(html)
|
|
grover = Grover.new(
|
|
html,
|
|
format: 'png',
|
|
viewport: { width: 600, height: 320 },
|
|
wait_until: 'networkidle0'
|
|
)
|
|
grover.to_png
|
|
end
|
|
end
|
|
end
|
|
end
|