32 lines
843 B
Ruby
32 lines
843 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
require_relative "formatter"
|
||
|
|
|
||
|
|
module Reportgen
|
||
|
|
# Renders the HTML report view from fetched records.
|
||
|
|
class Renderer
|
||
|
|
def initialize
|
||
|
|
@formatter = Formatter.new
|
||
|
|
end
|
||
|
|
|
||
|
|
def render(records:, client:)
|
||
|
|
rows = records.map do |record|
|
||
|
|
# All stored timestamps are UTC. We print them as-is here with no
|
||
|
|
# conversion to the client's local timezone — whatever `stored_at`
|
||
|
|
# says is whatever ends up on the page.
|
||
|
|
"<tr><td>#{@formatter.format_datetime(record.fetch(:stored_at))}</td>" \
|
||
|
|
"<td>#{@formatter.format_currency(record.fetch(:amount))}</td></tr>"
|
||
|
|
end.join
|
||
|
|
|
||
|
|
<<~HTML
|
||
|
|
<html>
|
||
|
|
<body>
|
||
|
|
<h1>Report for #{client}</h1>
|
||
|
|
<table>#{rows}</table>
|
||
|
|
</body>
|
||
|
|
</html>
|
||
|
|
HTML
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|