Class: Cards::TextWriter
Instance Method Summary collapse
- #create_card(name, color, cell) ⇒ Object
- #done ⇒ Object
-
#initialize ⇒ TextWriter
constructor
A new instance of TextWriter.
- #inspect ⇒ Object
- #show(card) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ TextWriter
Returns a new instance of TextWriter.
3 4 5 |
# File 'lib/cards/text_writer.rb', line 3 def initialize @rows = [] end |
Instance Method Details
#create_card(name, color, cell) ⇒ Object
11 12 13 |
# File 'lib/cards/text_writer.rb', line 11 def create_card(name, color, cell) (@rows[cell[1]] ||= [])[cell[0]] = name end |
#done ⇒ Object
15 16 |
# File 'lib/cards/text_writer.rb', line 15 def done end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/cards/text_writer.rb', line 22 def inspect @rows.map{|row| "|#{row.join("|")}|" }.join("\n") end |
#show(card) ⇒ Object
7 8 9 |
# File 'lib/cards/text_writer.rb', line 7 def show(card) create_card(card.name, card.color, card.cell) end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/cards/text_writer.rb', line 18 def to_s @rows.map{|row| row.map{|val| val ? val : " " }.join }.join("\n") end |