Class: Tundengine::Stages::Base
- Inherits:
-
Object
- Object
- Tundengine::Stages::Base
show all
- Defined in:
- lib/tundengine/stages/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent = Null.instance) ⇒ Base
Returns a new instance of Base.
7
8
9
10
11
12
13
|
# File 'lib/tundengine/stages/base.rb', line 7
def initialize(parent = Null.instance)
@parent = parent
@children = []
@rewinded = []
new_child_in_play!
@locked = false
end
|
Instance Attribute Details
#child_in_play ⇒ Object
Returns the value of attribute child_in_play.
5
6
7
|
# File 'lib/tundengine/stages/base.rb', line 5
def child_in_play
@child_in_play
end
|
#children ⇒ Object
Returns the value of attribute children.
5
6
7
|
# File 'lib/tundengine/stages/base.rb', line 5
def children
@children
end
|
#parent ⇒ Object
Returns the value of attribute parent.
5
6
7
|
# File 'lib/tundengine/stages/base.rb', line 5
def parent
@parent
end
|
Instance Method Details
#as_hash ⇒ Object
48
49
50
51
52
|
# File 'lib/tundengine/stages/base.rb', line 48
def as_hash
summary.merge(
children_key_name => children.map(&:as_hash)
)
end
|
#declare!(declaration = Declarations::Null.instance) ⇒ Object
15
16
17
|
# File 'lib/tundengine/stages/base.rb', line 15
def declare!(declaration = Declarations::Null.instance)
child_in_play.declare!(declaration)
end
|
#fast_forward!(n) ⇒ Object
44
45
46
|
# File 'lib/tundengine/stages/base.rb', line 44
def fast_forward!(n)
[n, @rewinded.length].min.times { children.push(@rewinded.shift) }
end
|
#lock! ⇒ Object
35
36
37
38
|
# File 'lib/tundengine/stages/base.rb', line 35
def lock!
@locked = true
parent.lock!
end
|
#on_complete_child! ⇒ Object
31
32
33
|
# File 'lib/tundengine/stages/base.rb', line 31
def on_complete_child!
children << child_in_play
end
|
#play!(card = Cards::Null.instance) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/tundengine/stages/base.rb', line 19
def play!(card = Cards::Null.instance)
completed = completed?
until completed or @locked
child_in_play.play!(card)
card = Cards::Null.instance
completed = completed?
completed ? on_completed! : new_child_in_play!
end
@locked = false
block_given? ? (yield self) : self
end
|
#rewind!(n) ⇒ Object
40
41
42
|
# File 'lib/tundengine/stages/base.rb', line 40
def rewind!(n)
[n, children.length].min.times { @rewinded.unshift(children.pop) }
end
|