-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.rb
54 lines (54 loc) · 986 Bytes
/
template.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
42
43
44
45
46
47
48
49
50
51
52
53
54
class Report
def initialize
@title = 'Monthly Report'
@text = ['Things are going', 'really really well']
end
def output_report
show_header
show_body
show_footer
end
def show_header
raise 'Called abstract method: show_header'
end
def show_body
raise 'Called abstract method: show_body'
end
def show_footer
raise 'Called abstract method: show_footer'
end
end
class HTMLReport < Report
def show_header
head = %Q{<html><head>
<title>#{@title}</title>
</head>}
puts head
end
def show_body
puts '<body>'
@text.each do |line|
puts '<li>' + line + '</li>'
end
puts '</body>'
end
def show_footer
puts '</html>'
end
end
class PlainTextReport < Report
def show_header
puts "***#{@title}***"
end
def show_body
@text.each do |line|
puts line
end
end
def show_footer
end
end
rep = HTMLReport.new
rep.output_report
rep = PlainTextReport.new
rep.output_report