ellington 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +37 -34
- data/README.md +8 -6
- data/Rakefile +1 -1
- data/lib/ellington/errros.rb +7 -20
- data/lib/ellington/line.rb +7 -10
- data/lib/ellington/line_info.rb +23 -17
- data/lib/ellington/passenger.rb +3 -3
- data/lib/ellington/route.rb +15 -17
- data/lib/ellington/route_info.rb +10 -7
- data/lib/ellington/station.rb +18 -5
- data/lib/ellington/station_info.rb +2 -3
- data/lib/ellington/version.rb +1 -1
- data/test/attendant_test.rb +2 -2
- data/test/conductor_test.rb +2 -2
- data/test/connection_test.rb +1 -1
- data/test/example.rb +21 -90
- data/test/line_info_test.rb +19 -20
- data/test/line_test.rb +2 -2
- data/test/logger_test.rb +1 -1
- data/test/passenger_test.rb +6 -6
- data/test/route_info_test.rb +7 -12
- data/test/route_test.rb +2 -2
- data/test/station_info_test.rb +3 -8
- data/test/station_test.rb +6 -6
- data/test/target_test.rb +5 -5
- data/test/test_helper.rb +5 -5
- data/test/ticket_test.rb +2 -2
- data/test/transition_info_test.rb +2 -2
- data/test/unique_type_array_test.rb +1 -1
- metadata +47 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1047c36cb4128e723415dcd5e7b74f00a38da00b
|
4
|
+
data.tar.gz: 8077a60871b70d5530847a5f78a653ca9236a11e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f78a52f1504888e376e61e788eb9bb5ac3aafe5e2b2285ba346bb0d9bfed999ebd1c0c8a860befb9d223520c5adef146852cbd012dc8258aae4079cb4e2d3b9
|
7
|
+
data.tar.gz: 44c136a470a26cb649a78285d45728eefd5e4d8dd95197beb4f73182f0c106f5364f67442ca9b962b8bf9a07d48c83395b63eef6506a2c0ae22ff079daebfa90
|
data/Gemfile.lock
CHANGED
@@ -1,57 +1,60 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ellington (0.
|
5
|
-
hero (~> 0.
|
6
|
-
ruby-graphviz (~> 1.
|
7
|
-
state_jacket (~> 0.1.
|
4
|
+
ellington (0.2.0)
|
5
|
+
hero (~> 0.2.0)
|
6
|
+
ruby-graphviz (~> 1.2.1)
|
7
|
+
state_jacket (~> 0.1.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
awesome_print (1.
|
12
|
+
awesome_print (1.2.0)
|
13
13
|
binding_of_caller (0.7.2)
|
14
14
|
debug_inspector (>= 0.0.1)
|
15
|
-
coderay (1.0
|
16
|
-
|
17
|
-
coveralls (0.6.7)
|
18
|
-
colorize
|
15
|
+
coderay (1.1.0)
|
16
|
+
coveralls (0.7.2)
|
19
17
|
multi_json (~> 1.3)
|
20
|
-
rest-client
|
18
|
+
rest-client (= 1.6.7)
|
21
19
|
simplecov (>= 0.7)
|
22
|
-
|
20
|
+
term-ansicolor (= 1.2.2)
|
21
|
+
thor (= 0.18.1)
|
23
22
|
debug_inspector (0.0.2)
|
24
|
-
|
25
|
-
|
23
|
+
docile (1.1.5)
|
24
|
+
hero (0.2.0)
|
25
|
+
interception (0.5)
|
26
26
|
method_source (0.8.2)
|
27
|
-
|
28
|
-
|
29
|
-
os
|
30
|
-
mime-types (1.24)
|
31
|
-
multi_json (1.7.9)
|
27
|
+
mime-types (2.4.3)
|
28
|
+
multi_json (1.10.1)
|
32
29
|
os (0.9.6)
|
33
|
-
pry (0.
|
34
|
-
coderay (~> 1.0
|
35
|
-
method_source (~> 0.8)
|
30
|
+
pry (0.10.1)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.8.1)
|
36
33
|
slop (~> 3.4)
|
37
|
-
pry-rescue (1.
|
38
|
-
interception (>= 0.
|
34
|
+
pry-rescue (1.4.1)
|
35
|
+
interception (>= 0.5)
|
39
36
|
pry
|
40
37
|
pry-stack_explorer (0.4.9.1)
|
41
38
|
binding_of_caller (>= 0.7)
|
42
39
|
pry (>= 0.9.11)
|
43
|
-
|
40
|
+
pry-test (0.5.5)
|
41
|
+
os
|
42
|
+
rake (10.4.2)
|
44
43
|
rest-client (1.6.7)
|
45
44
|
mime-types (>= 1.16)
|
46
|
-
ruby-graphviz (1.
|
47
|
-
simplecov (0.
|
45
|
+
ruby-graphviz (1.2.1)
|
46
|
+
simplecov (0.9.1)
|
47
|
+
docile (~> 1.1.0)
|
48
48
|
multi_json (~> 1.0)
|
49
|
-
simplecov-html (~> 0.
|
50
|
-
simplecov-html (0.
|
51
|
-
slop (3.
|
52
|
-
|
49
|
+
simplecov-html (~> 0.8.0)
|
50
|
+
simplecov-html (0.8.0)
|
51
|
+
slop (3.6.0)
|
52
|
+
spoof (2.0.1)
|
53
|
+
state_jacket (0.1.1)
|
54
|
+
term-ansicolor (1.2.2)
|
55
|
+
tins (~> 0.8)
|
53
56
|
thor (0.18.1)
|
54
|
-
|
57
|
+
tins (0.13.2)
|
55
58
|
|
56
59
|
PLATFORMS
|
57
60
|
ruby
|
@@ -60,10 +63,10 @@ DEPENDENCIES
|
|
60
63
|
awesome_print
|
61
64
|
coveralls
|
62
65
|
ellington!
|
63
|
-
|
64
|
-
micro_test
|
66
|
+
pry
|
65
67
|
pry-rescue
|
66
68
|
pry-stack_explorer
|
69
|
+
pry-test
|
67
70
|
rake
|
68
71
|
simplecov
|
69
|
-
|
72
|
+
spoof
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-932-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
|
+
[![Code Status](http://img.shields.io/codeclimate/github/hopsoft/ellington.svg?style=flat)](https://codeclimate.com/github/hopsoft/ellington)
|
3
|
+
[![Dependency Status](http://img.shields.io/gemnasium/hopsoft/ellington.svg?style=flat)](https://gemnasium.com/hopsoft/ellington)
|
4
|
+
[![Build Status](http://img.shields.io/travis/hopsoft/ellington.svg?style=flat)](https://travis-ci.org/hopsoft/ellington)
|
5
|
+
[![Coverage Status](https://img.shields.io/coveralls/hopsoft/ellington.svg?style=flat)](https://coveralls.io/r/hopsoft/ellington?branch=master)
|
6
|
+
[![Downloads](http://img.shields.io/gem/dt/ellington.svg?style=flat)](http://rubygems.org/gems/ellington)
|
2
7
|
|
3
|
-
|
4
|
-
[![Dependency Status](https://gemnasium.com/hopsoft/ellington.png)](https://gemnasium.com/hopsoft/ellington)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/hopsoft/ellington.png)](https://codeclimate.com/github/hopsoft/ellington)
|
6
|
-
[![Coverage Status](https://coveralls.io/repos/hopsoft/ellington/badge.png?branch=master)](https://coveralls.io/r/hopsoft/ellington?branch=master)
|
8
|
+
# Ellington
|
7
9
|
|
8
10
|
Named after [Duke Ellington](http://www.dukeellington.com/) whose signature tune was ["Take the 'A' Train"](http://en.wikipedia.org/wiki/Take_the_%22A%22_Train).
|
9
11
|
The song was written about [New York City's A train](http://en.wikipedia.org/wiki/A_%28New_York_City_Subway_service%29).
|
@@ -12,7 +14,7 @@ The song was written about [New York City's A train](http://en.wikipedia.org/wik
|
|
12
14
|
|
13
15
|
#### Ellington is an architecture for modeling complex business processes.
|
14
16
|
|
15
|
-
Ellington
|
17
|
+
Ellington brings discipline, organization, and modularity to a project.
|
16
18
|
|
17
19
|
The nomenclature is taken from [New York's subway system](http://en.wikipedia.org/wiki/New_York_City_Subway).
|
18
20
|
We've found that using consistent and cohesive physical metaphors helps people reason more clearly about the complexities of software.
|
data/Rakefile
CHANGED
data/lib/ellington/errros.rb
CHANGED
@@ -1,22 +1,9 @@
|
|
1
1
|
module Ellington
|
2
|
-
class ListAlreadyContainsType < StandardError
|
3
|
-
end
|
4
|
-
|
5
|
-
class
|
6
|
-
end
|
7
|
-
|
8
|
-
class
|
9
|
-
end
|
10
|
-
|
11
|
-
class NotImplementedError < StandardError
|
12
|
-
end
|
13
|
-
|
14
|
-
class NoStationsDeclared < StandardError
|
15
|
-
end
|
16
|
-
|
17
|
-
class NoLinesDeclared < StandardError
|
18
|
-
end
|
19
|
-
|
20
|
-
class NoGoalDeclared < StandardError
|
21
|
-
end
|
2
|
+
class ListAlreadyContainsType < StandardError; end
|
3
|
+
class AttendantDisapproves < StandardError; end
|
4
|
+
class InvalidStateTransition < StandardError; end
|
5
|
+
class NotImplementedError < StandardError; end
|
6
|
+
class NoStationsDeclared < StandardError; end
|
7
|
+
class NoLinesDeclared < StandardError; end
|
8
|
+
class NoGoalDeclared < StandardError; end
|
22
9
|
end
|
data/lib/ellington/line.rb
CHANGED
@@ -46,8 +46,8 @@ module Ellington
|
|
46
46
|
stations.first.initial_states
|
47
47
|
end
|
48
48
|
|
49
|
-
def board(passenger
|
50
|
-
formula.run passenger
|
49
|
+
def board(passenger)
|
50
|
+
formula.run passenger
|
51
51
|
end
|
52
52
|
|
53
53
|
def boarded?(passenger)
|
@@ -94,24 +94,21 @@ module Ellington
|
|
94
94
|
return complete_line(line_info)
|
95
95
|
end
|
96
96
|
|
97
|
-
log line_info
|
98
|
-
if line_info.passenger.current_state == line_info.station.errored
|
99
|
-
Ellington.logger.info "\n" if Ellington.logger
|
100
|
-
end
|
97
|
+
log line_info.station_completed_message # TODO: add *passenger_attrs
|
101
98
|
end
|
102
99
|
|
103
100
|
protected
|
104
101
|
|
105
102
|
def complete_line(line_info)
|
106
|
-
log line_info
|
107
|
-
log line_info
|
103
|
+
log line_info.station_completed_message # TODO: add *passenger_attrs
|
104
|
+
log line_info.line_completed_message # TODO: add *passenger_attrs
|
108
105
|
changed
|
109
106
|
notify_observers line_info
|
110
107
|
end
|
111
108
|
|
112
|
-
def log(
|
109
|
+
def log(message)
|
113
110
|
return unless Ellington.logger
|
114
|
-
Ellington.logger.info
|
111
|
+
Ellington.logger.info message
|
115
112
|
end
|
116
113
|
|
117
114
|
end
|
data/lib/ellington/line_info.rb
CHANGED
@@ -14,25 +14,31 @@ module Ellington
|
|
14
14
|
@station_full_name ||= "#{line.route.name} #{line.class.name} #{station.class.name}"
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def station_completed_message
|
18
18
|
message = []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
line.
|
30
|
-
|
31
|
-
|
32
|
-
line.route.log_options[:options].each do |attr|
|
33
|
-
message << "[#{attr}:#{self.options[attr]}]"
|
34
|
-
end
|
19
|
+
message << "[STATION COMPLETED]"
|
20
|
+
message << "[#{station.state(passenger)}]"
|
21
|
+
message << "[#{station_full_name}]"
|
22
|
+
message.concat passenger_message
|
23
|
+
message.join " "
|
24
|
+
end
|
25
|
+
|
26
|
+
def line_completed_message
|
27
|
+
message = []
|
28
|
+
message << "[LINE COMPLETED]"
|
29
|
+
message << "[#{line.state(passenger)}]"
|
30
|
+
message << "[#{line.name}]"
|
31
|
+
message.concat passenger_message
|
35
32
|
message.join " "
|
36
33
|
end
|
34
|
+
|
35
|
+
def passenger_message
|
36
|
+
line.route.passenger_attrs_to_log.reduce([]) do |memo, attr|
|
37
|
+
value = passenger.send(attr) rescue nil
|
38
|
+
memo << "[#{attr}:#{value}]" unless value.nil?
|
39
|
+
memo
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
37
43
|
end
|
38
44
|
end
|
data/lib/ellington/passenger.rb
CHANGED
@@ -6,11 +6,11 @@ module Ellington
|
|
6
6
|
attr_accessor :context, :ticket
|
7
7
|
attr_reader :route, :state_history
|
8
8
|
|
9
|
-
def initialize(context, route,
|
9
|
+
def initialize(context, route: route, ticket: Ellington::Ticket.new, state_history: [])
|
10
10
|
@context = context
|
11
11
|
@route = route
|
12
|
-
@ticket =
|
13
|
-
@state_history =
|
12
|
+
@ticket = ticket
|
13
|
+
@state_history = state_history
|
14
14
|
super context
|
15
15
|
end
|
16
16
|
|
data/lib/ellington/route.rb
CHANGED
@@ -47,8 +47,8 @@ module Ellington
|
|
47
47
|
@initialized
|
48
48
|
end
|
49
49
|
|
50
|
-
def board(passenger
|
51
|
-
lines.first.board passenger
|
50
|
+
def board(passenger)
|
51
|
+
lines.first.board passenger
|
52
52
|
end
|
53
53
|
|
54
54
|
def lines
|
@@ -92,18 +92,17 @@ module Ellington
|
|
92
92
|
@connections ||= Ellington::ConnectionList.new
|
93
93
|
end
|
94
94
|
|
95
|
-
def connect_to(line,
|
96
|
-
|
97
|
-
|
98
|
-
connections << Ellington::Connection.new(line, type, states)
|
95
|
+
def connect_to(line, if_any: [], if_all: [])
|
96
|
+
connections << Ellington::Connection.new(line, :if_any, if_any) unless if_any.empty?
|
97
|
+
connections << Ellington::Connection.new(line, :if_all, if_all) unless if_all.empty?
|
99
98
|
end
|
100
99
|
|
101
|
-
def
|
102
|
-
@
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
def passenger_attrs_to_log
|
101
|
+
@passenger_attrs_to_log ||= []
|
102
|
+
end
|
103
|
+
|
104
|
+
def set_passenger_attrs_to_log(*attrs)
|
105
|
+
@passenger_attrs_to_log = attrs
|
107
106
|
end
|
108
107
|
|
109
108
|
def line_completed(line_info)
|
@@ -111,7 +110,7 @@ module Ellington
|
|
111
110
|
connections = required_connections(route_info.passenger)
|
112
111
|
return complete_route(route_info) if connections.empty?
|
113
112
|
connections.each do |connection|
|
114
|
-
connection.line.board route_info.passenger
|
113
|
+
connection.line.board route_info.passenger
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
@@ -119,11 +118,10 @@ module Ellington
|
|
119
118
|
|
120
119
|
def complete_route(route_info)
|
121
120
|
if passed.satisfied?(route_info.passenger) || failed.satisfied?(route_info.passenger)
|
122
|
-
log route_info
|
121
|
+
log route_info.route_completed_message
|
123
122
|
changed
|
124
123
|
notify_observers route_info
|
125
124
|
end
|
126
|
-
Ellington.logger.info "\n" if Ellington.logger
|
127
125
|
end
|
128
126
|
|
129
127
|
def required_connections(passenger)
|
@@ -132,9 +130,9 @@ module Ellington
|
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
|
-
def log(
|
133
|
+
def log(message)
|
136
134
|
return unless Ellington.logger
|
137
|
-
Ellington.logger.info
|
135
|
+
Ellington.logger.info message
|
138
136
|
end
|
139
137
|
|
140
138
|
end
|
data/lib/ellington/route_info.rb
CHANGED
@@ -10,19 +10,22 @@ module Ellington
|
|
10
10
|
super line_info
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def route_completed_message
|
14
14
|
message = []
|
15
15
|
message << "[ROUTE COMPLETED]"
|
16
16
|
message << "[#{route.state(passenger)}]"
|
17
17
|
message << "[#{route.name}]"
|
18
|
-
|
19
|
-
message << "[#{attr}:#{passenger.send(attr)}]"
|
20
|
-
end
|
21
|
-
route.log_options[:options].each do |attr|
|
22
|
-
message << "[#{attr}:#{self.options[attr]}]"
|
23
|
-
end
|
18
|
+
message.concat passenger_message
|
24
19
|
message.join " "
|
25
20
|
end
|
21
|
+
|
22
|
+
def passenger_message
|
23
|
+
route.passenger_attrs_to_log.reduce([]) do |memo, attr|
|
24
|
+
value = passenger.send(attr) rescue nil
|
25
|
+
memo << "[#{attr}:#{value}]" unless value.nil?
|
26
|
+
memo
|
27
|
+
end
|
28
|
+
end
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
data/lib/ellington/station.rb
CHANGED
@@ -46,25 +46,38 @@ module Ellington
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def can_engage?(passenger
|
49
|
+
def can_engage?(passenger)
|
50
50
|
return false unless route.states.can_transition?(passenger.current_state => states.keys)
|
51
51
|
return false if passenger.state_history_includes?(passed)
|
52
52
|
true
|
53
53
|
end
|
54
54
|
|
55
|
-
def engage(passenger
|
55
|
+
def engage(passenger)
|
56
56
|
raise Ellington::NotImplementedError
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def engage_and_transition(passenger)
|
60
|
+
begin
|
61
|
+
if !!engage(passenger)
|
62
|
+
pass_passenger passenger
|
63
|
+
else
|
64
|
+
fail_passenger passenger
|
65
|
+
end
|
66
|
+
rescue StandardError => e
|
67
|
+
Ellington.logger.error "Failure while engaging passenger! #{e}" if Ellington.logger
|
68
|
+
error_passenger passenger
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def call(passenger, _=nil)
|
60
73
|
if can_engage?(passenger)
|
61
74
|
attendant = Ellington::Attendant.new(self)
|
62
75
|
passenger.add_observer attendant
|
63
|
-
|
76
|
+
engage_and_transition passenger
|
64
77
|
passenger.delete_observer attendant
|
65
78
|
raise Ellington::AttendantDisapproves unless attendant.approve?
|
66
79
|
changed
|
67
|
-
notify_observers Ellington::StationInfo.new(self, passenger, attendant.passenger_transitions.first
|
80
|
+
notify_observers Ellington::StationInfo.new(self, passenger, attendant.passenger_transitions.first)
|
68
81
|
end
|
69
82
|
|
70
83
|
passenger
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Ellington
|
2
2
|
class StationInfo
|
3
|
-
attr_reader :station, :passenger, :transition
|
4
|
-
def initialize(station, passenger, transition
|
3
|
+
attr_reader :station, :passenger, :transition
|
4
|
+
def initialize(station, passenger, transition)
|
5
5
|
@station = station
|
6
6
|
@passenger = passenger
|
7
7
|
@transition = transition
|
8
|
-
@options = options
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
data/lib/ellington/version.rb
CHANGED
data/test/attendant_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class AttendantTest <
|
3
|
+
class AttendantTest < PryTest::Test
|
4
4
|
|
5
5
|
before do
|
6
6
|
route = BasicMath.new
|
7
7
|
line = route.lines.first
|
8
8
|
@station = line.stations.first
|
9
|
-
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), route)
|
9
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), route: route)
|
10
10
|
@passenger.current_state = route.initial_state
|
11
11
|
@attendant = Ellington::Attendant.new(@station)
|
12
12
|
@passenger.add_observer @attendant
|
data/test/conductor_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class ConductorTest <
|
3
|
+
class ConductorTest < PryTest::Test
|
4
4
|
|
5
5
|
before do
|
6
6
|
@route = BasicMath.new
|
7
7
|
@conductor = Ellington::Conductor.new(@route)
|
8
|
-
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
8
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), route: @route)
|
9
9
|
@passenger.current_state = @route.initial_state
|
10
10
|
end
|
11
11
|
|
data/test/connection_test.rb
CHANGED
data/test/example.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
require "logger"
|
2
2
|
require_relative "../lib/ellington"
|
3
3
|
|
4
|
-
#require "yell"
|
5
|
-
#Ellington.logger = Yell.new do |logger|
|
6
|
-
# logger.adapter STDOUT, :level => [:info], :format => "%m"
|
7
|
-
#end
|
8
|
-
#Ellington.logger = Logger.new($stdout)
|
9
|
-
|
10
4
|
class NumberWithHistory
|
11
5
|
attr_reader :original_value, :current_value, :history
|
12
6
|
def initialize(value)
|
@@ -25,128 +19,65 @@ end
|
|
25
19
|
|
26
20
|
# stations -----------------------------------------------------------------
|
27
21
|
class Add10 < Ellington::Station
|
28
|
-
def engage(number
|
22
|
+
def engage(number)
|
29
23
|
raise if rand(100) == 0
|
30
|
-
if rand(100) > 5
|
31
|
-
number.calc :+, 10
|
32
|
-
pass_passenger number
|
33
|
-
else
|
34
|
-
fail_passenger number
|
35
|
-
end
|
36
|
-
rescue
|
37
|
-
error_passenger number
|
24
|
+
number.calc :+, 10 if rand(100) > 5
|
38
25
|
end
|
39
26
|
end
|
40
27
|
|
41
28
|
class Add100 < Ellington::Station
|
42
|
-
def engage(number
|
29
|
+
def engage(number)
|
43
30
|
raise if rand(100) == 0
|
44
|
-
if rand(100) > 5
|
45
|
-
number.calc :+, 100
|
46
|
-
pass_passenger number
|
47
|
-
else
|
48
|
-
fail_passenger number
|
49
|
-
end
|
50
|
-
rescue
|
51
|
-
error_passenger number
|
31
|
+
number.calc :+, 100 if rand(100) > 5
|
52
32
|
end
|
53
33
|
end
|
54
34
|
|
55
35
|
class Add1000 < Ellington::Station
|
56
|
-
def engage(number
|
36
|
+
def engage(number)
|
57
37
|
raise if rand(100) == 0
|
58
|
-
if rand(100) > 5
|
59
|
-
number.calc :+, 1000
|
60
|
-
pass_passenger number
|
61
|
-
else
|
62
|
-
fail_passenger number
|
63
|
-
end
|
64
|
-
rescue
|
65
|
-
error_passenger number
|
38
|
+
number.calc :+, 1000 if rand(100) > 5
|
66
39
|
end
|
67
40
|
end
|
68
41
|
|
69
42
|
class MultiplyBy10 < Ellington::Station
|
70
|
-
def engage(number
|
43
|
+
def engage(number)
|
71
44
|
raise if rand(100) == 0
|
72
|
-
if rand(100) > 5
|
73
|
-
number.calc :*, 10
|
74
|
-
pass_passenger number
|
75
|
-
else
|
76
|
-
fail_passenger number
|
77
|
-
end
|
78
|
-
rescue
|
79
|
-
error_passenger number
|
45
|
+
number.calc :*, 10 if rand(100) > 5
|
80
46
|
end
|
81
47
|
end
|
82
48
|
|
83
49
|
class MultiplyBy100 < Ellington::Station
|
84
|
-
def engage(number
|
50
|
+
def engage(number)
|
85
51
|
raise if rand(100) == 0
|
86
|
-
if rand(100) > 5
|
87
|
-
number.calc :*, 100
|
88
|
-
pass_passenger number
|
89
|
-
else
|
90
|
-
fail_passenger number
|
91
|
-
end
|
92
|
-
rescue
|
93
|
-
error_passenger number
|
52
|
+
number.calc :*, 100 if rand(100) > 5
|
94
53
|
end
|
95
54
|
end
|
96
55
|
|
97
56
|
class MultiplyBy1000 < Ellington::Station
|
98
|
-
def engage(number
|
57
|
+
def engage(number)
|
99
58
|
raise if rand(100) == 0
|
100
|
-
if rand(100) > 5
|
101
|
-
number.calc :*, 1000
|
102
|
-
pass_passenger number
|
103
|
-
else
|
104
|
-
fail_passenger number
|
105
|
-
end
|
106
|
-
rescue
|
107
|
-
error_passenger number
|
59
|
+
number.calc :*, 1000 if rand(100) > 5
|
108
60
|
end
|
109
61
|
end
|
110
62
|
|
111
63
|
class DivideBy10 < Ellington::Station
|
112
|
-
def engage(number
|
64
|
+
def engage(number)
|
113
65
|
raise if rand(100) == 0
|
114
|
-
if rand(100) > 5
|
115
|
-
number.calc :/, 10.0
|
116
|
-
pass_passenger number
|
117
|
-
else
|
118
|
-
fail_passenger number
|
119
|
-
end
|
120
|
-
rescue
|
121
|
-
error_passenger number
|
66
|
+
number.calc :/, 10.0 if rand(100) > 5
|
122
67
|
end
|
123
68
|
end
|
124
69
|
|
125
70
|
class DivideBy100 < Ellington::Station
|
126
|
-
def engage(number
|
71
|
+
def engage(number)
|
127
72
|
raise if rand(100) == 0
|
128
|
-
if rand(100) > 5
|
129
|
-
number.calc :/, 100.0
|
130
|
-
pass_passenger number
|
131
|
-
else
|
132
|
-
fail_passenger number
|
133
|
-
end
|
134
|
-
rescue
|
135
|
-
error_passenger number
|
73
|
+
number.calc :/, 100.0 if rand(100) > 5
|
136
74
|
end
|
137
75
|
end
|
138
76
|
|
139
77
|
class DivideBy1000 < Ellington::Station
|
140
|
-
def engage(number
|
78
|
+
def engage(number)
|
141
79
|
raise if rand(100) == 0
|
142
|
-
if rand(100) > 5
|
143
|
-
number.calc :/, 1000.0
|
144
|
-
pass_passenger number
|
145
|
-
else
|
146
|
-
fail_passenger number
|
147
|
-
end
|
148
|
-
rescue
|
149
|
-
error_passenger number
|
80
|
+
number.calc :/, 1000.0 if rand(100) > 5
|
150
81
|
end
|
151
82
|
end
|
152
83
|
|
@@ -174,9 +105,9 @@ end
|
|
174
105
|
|
175
106
|
# route -------------------------------------------------------------------
|
176
107
|
class BasicMath < Ellington::Route
|
177
|
-
addition
|
108
|
+
addition = Addition.new
|
178
109
|
multiplication = Multiplication.new
|
179
|
-
division
|
110
|
+
division = Division.new
|
180
111
|
|
181
112
|
lines << addition
|
182
113
|
lines << division
|
@@ -187,6 +118,6 @@ class BasicMath < Ellington::Route
|
|
187
118
|
connect_to division, :if_any => addition.passed
|
188
119
|
connect_to multiplication, :if_any => addition.failed
|
189
120
|
|
190
|
-
|
121
|
+
set_passenger_attrs_to_log :original_value, :current_value
|
191
122
|
end
|
192
123
|
|