forked from mixandgo/template_pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.rb
41 lines (36 loc) · 845 Bytes
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "date"
require "json"
class Report
class << self
def call(data, format: nil)
case format
when :html
<<~HTML
<!DOCTYPE html>
<head><title>#{header}</title></head>
<html>
<body>#{data}</body>
<footer>#{footer}</footer>
</html>
HTML
when :json
{ title: header, body: data, footer: footer }.to_json
else
<<~END
#{header}
#{spacer}
#{data}
#{spacer}
#{footer}
END
end
end
private
def header = "#{year} Report"
def footer = "#{year} @ Copyright Acme Inc."
def spacer = "#{'-' * 72}"
def year = Date.today.year.to_s
end
end
data = "This is some data I want to put in my report"
puts Report.call(data, format: :json)