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