Created
March 7, 2011 15:08
-
-
Save ttreitlinger/858605 to your computer and use it in GitHub Desktop.
report.rb
This file contains 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
class Report | |
def initialize deck, pile, players | |
@deck = deck | |
@pile = pile | |
@players = players | |
output_report | |
end | |
# template method | |
def output_report | |
output_start | |
output_head | |
output_body_start | |
output_body | |
output_body_end | |
output_end | |
hook_report_finished | |
end | |
# a final method | |
def output_end | |
puts 'report generated' | |
end | |
# a sample hook method | |
def hook_report_finished | |
end | |
end | |
class TextReport < Report | |
def output_start | |
puts 'generating report in text format' | |
end | |
def output_head | |
puts '========== current state of game - plain text ===========' | |
end | |
def output_body_start | |
end | |
def output_body | |
@players.each do |player| | |
puts player.to_string | |
end | |
puts "Deck contains: #{@deck.to_string}" | |
puts "Pile contains: #{@pile.to_string}" | |
end | |
def output_body_end | |
puts '=========================================================' | |
puts '' | |
end | |
end | |
class HtmlReport < Report | |
def output_start | |
puts 'generating report in html format' | |
end | |
def output_head | |
puts '<html>' | |
puts '<head>Current state of game</head>' | |
end | |
def output_body_start | |
puts '<body>' | |
end | |
def output_body | |
puts '<ul>' | |
@players.each do |player| | |
puts "<li>#{player.to_string}</li>" | |
end | |
puts '</ul>' | |
puts "<p>Deck contains: #{@deck.to_string}</p>" | |
puts "<p>Pile contains: #{@pile.to_string}</p>" | |
end | |
def output_body_end | |
puts '</body>' | |
end | |
def output_end | |
puts '</html>' | |
puts '' | |
end | |
end | |
class PdfReport < Report | |
def output_start | |
puts 'generating report in pdf format' | |
end | |
def output_head | |
end | |
def output_body_start | |
end | |
def output_body | |
puts '<pdf>......</pdf>' | |
end | |
def output_body_end | |
end | |
def output_end | |
puts 'end of pdf format' | |
puts '' | |
end | |
def hook_report_finished | |
puts 'pdf generator overriding hook method' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment