Class: Cards::CardWall
Defined Under Namespace
Classes: DefinitionContext
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CardWall.
33
34
35
36
37
38
39
40
|
# File 'lib/cards/card_wall.rb', line 33
def initialize
@handlers = []
@layouts = []
@root = Card.new("root")
@root.layout = RowLayout.new
@root.y = -1
@last_cards = [@root]
end
|
Class Method Details
14
15
16
17
18
19
20
21
|
# File 'lib/cards/card_wall.rb', line 14
def self.colors
@colors ||= {
:role => :blue,
:activity => :blue,
:task => :red,
:story => :yellow
}
end
|
.from(parser, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/cards/card_wall.rb', line 23
def self.from(parser, &block)
builder = self.new.define(&block)
parser.each_row do |row|
builder.process(row)
end
builder.show(@writer_class.new(parser.default_output_file))
end
|
.writer=(writer_class) ⇒ Object
10
11
12
|
# File 'lib/cards/card_wall.rb', line 10
def self.writer=(writer_class)
@writer_class = writer_class
end
|
Instance Method Details
#add_handler(type, layout, &block) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/cards/card_wall.rb', line 50
def add_handler(type, layout, &block)
i = @handlers.size
@handlers << type
@root.layout = layout if @layouts.empty?
@layouts << layout
(class << self; self; end).module_eval do
define_method("add_#{type}") do |name, row|
card = yield(name, row)
card.layout = @layouts[i+1]
card.color ||= CardWall.colors[type] || :white
@last_cards[i].add(card)
@last_cards[i+1] = card
end
end
end
|
#define(&block) ⇒ Object
5
6
7
8
|
# File 'lib/cards/card_wall.rb', line 5
def define(&block)
DefinitionContext.new(self).instance_eval(&block)
self
end
|
#process(row) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/cards/card_wall.rb', line 42
def process(row)
@handlers.each do |handler|
unless row[handler].blank?
send("add_#{handler}", row[handler], row)
end
end
end
|
#show(output) ⇒ Object
66
67
68
69
70
|
# File 'lib/cards/card_wall.rb', line 66
def show(output)
@root.layout
@root.visit {|card| output.create_card(card.name, card.color, card.cell) unless card == @root}
output.done
end
|