Created
March 5, 2012 14:25
-
-
Save takaheraw/1978518 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class Report | |
def initialize | |
@title = "月次報告" | |
@text = ["順調","最高の調子"] | |
end | |
def output_report | |
output_start | |
output_head | |
output_body_start | |
output_body | |
output_body_end | |
output_end | |
end | |
def output_body | |
@text.each do |line| | |
output_line(line) | |
end | |
end | |
def output_start | |
end | |
def output_head | |
output_line(@title) | |
end | |
def output_body_start | |
end | |
def output_line(line) | |
raise 'Called abstract method: output_line' | |
end | |
def output_body_end | |
end | |
def output_end | |
end | |
end | |
class HTMLReport < Report | |
def output_start | |
puts '<html>' | |
end | |
def output_head | |
puts '<head>' | |
puts "<title>#{@title}</title>" | |
puts '</head>' | |
end | |
def output_body_start | |
puts '<body>' | |
end | |
def output_line(line) | |
puts "<p>#{line}</p>" | |
end | |
def output_body_end | |
puts '</body>' | |
end | |
def output_end | |
puts '</html>' | |
end | |
end | |
class PlainTextReport < Report | |
def output_start | |
end | |
def output_head | |
puts "****#{@title}****" | |
puts | |
end | |
def output_body_start | |
end | |
def output_line(line) | |
puts line | |
end | |
def output_body_end | |
end | |
def output_end | |
end | |
end | |
report = HTMLReport.new | |
report.output_report | |
report = PlainTextReport.new | |
report.output_report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment