Class: Ellington::Line
- Inherits:
-
Object
show all
- Extended by:
- Forwardable, Observable
- Includes:
- HasTargets, Observable
- Defined in:
- lib/ellington/line.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasTargets
#error_target, #fail_target, #state, #state_names
Constructor Details
#initialize ⇒ Line
Returns a new instance of Line.
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ellington/line.rb', line 32
def initialize
if stations.empty?
message = "#{self.class.name} has no stations!"
raise Ellington::NoStationsDeclared.new(message)
end
if goal.empty?
message = "#{self.class.name} has no goal!"
raise Ellington::NoGoalDeclared.new(message)
end
end
|
Instance Attribute Details
#route ⇒ Object
Returns the value of attribute route.
24
25
26
|
# File 'lib/ellington/line.rb', line 24
def route
@route
end
|
#route_class ⇒ Object
Returns the value of attribute route_class.
24
25
26
|
# File 'lib/ellington/line.rb', line 24
def route_class
@route_class
end
|
Class Method Details
.pass_target(*states) ⇒ Object
Also known as:
passed, goal
13
14
15
|
# File 'lib/ellington/line.rb', line 13
def pass_target(*states)
@goal ||= Ellington::Target.new(*states)
end
|
Instance Method Details
#board(passenger, options = {}) ⇒ Object
44
45
46
|
# File 'lib/ellington/line.rb', line 44
def board(passenger, options={})
formula.run passenger, options
end
|
#boarded?(passenger) ⇒ Boolean
48
49
50
|
# File 'lib/ellington/line.rb', line 48
def boarded?(passenger)
!(passenger.state_history & states.keys).empty?
end
|
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ellington/line.rb', line 56
def formula
@formula ||= begin
Hero::Formula[name]
Hero::Formula[name].steps.clear
stations.each do |station|
Hero::Formula[name].add_step station
end
Hero::Formula[name]
end
end
|
#name ⇒ Object
52
53
54
|
# File 'lib/ellington/line.rb', line 52
def name
@name ||= "#{self.class.name}::#{route_class.name}"
end
|
#states ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/ellington/line.rb', line 67
def states
@states ||= begin
catalog = StateJacket::Catalog.new
stations.each_with_index do |station, index|
station.states.each do |state, transitions|
catalog[state] = transitions.nil? ? nil : transitions.dup
end
if index < stations.length - 1
next_station = stations[index + 1]
catalog[station.passed] = next_station.states.keys
end
end
catalog.lock
catalog
end
end
|
#station_completed(station_info) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/ellington/line.rb', line 85
def station_completed(station_info)
line_info = Ellington::LineInfo.new(self, station_info)
if line_info.station == stations.last ||
line_info.passenger.current_state == line_info.station.failed
log line_info, :station_completed => true
log line_info, :line_completed => true
changed
notify_observers line_info
else
log line_info, :station_completed => true
if line_info.passenger.current_state == line_info.station.errored
Ellington.logger.info "\n" if Ellington.logger
end
end
end
|