Class: Cards::TextWriter

Inherits:
Object show all
Defined in:
lib/cards/text_writer.rb

Instance Method Summary collapse

Constructor Details

#initializeTextWriter

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

#doneObject



15
16
# File 'lib/cards/text_writer.rb', line 15

def done
end

#inspectObject



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_sObject



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