MonkeyEngine 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +192 -0
- data/CHANGELOG.md +9 -4
- data/Gemfile.lock +14 -15
- data/lib/Action/action.rb +0 -2
- data/lib/Monkey/monkey.rb +1 -2
- data/lib/MonkeyAction/monkey_action.rb +0 -2
- data/lib/MonkeyAction/monkey_action_dead.rb +1 -3
- data/lib/MonkeyAction/monkey_action_eat.rb +1 -3
- data/lib/MonkeyAction/monkey_action_pause.rb +1 -3
- data/lib/MonkeyAction/monkey_action_sleep.rb +1 -3
- data/lib/MonkeyAction/monkey_action_type.rb +5 -7
- data/lib/MonkeyAction/monkey_action_wake.rb +1 -3
- data/lib/MonkeyAction/monkey_timed_action.rb +2 -4
- data/lib/MonkeyEngine/action_rules.rb +1 -1
- data/lib/MonkeyEngine/monkey_engine.rb +2 -8
- data/lib/MonkeyEngine/version.rb +1 -1
- data/lib/MonkeyKeyboard/keyboard_char.rb +0 -1
- data/lib/MonkeyKeyboard/keyboard_key.rb +9 -9
- data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +1 -1
- data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +2 -2
- data/lib/MonkeyManager/monkey_manager.rb +5 -5
- data/lib/tasks/engine.rb +11 -7
- data/monkeyengine.gemspec +5 -1
- data/spec/action_rules_spec.rb +8 -14
- data/spec/engine_spec.rb +10 -10
- data/spec/keyboard_char_spec.rb +1 -1
- data/spec/keyboard_key_spec.rb +5 -5
- data/spec/monkey_action_eat_spec.rb +8 -8
- data/spec/monkey_action_pause_spec.rb +9 -9
- data/spec/monkey_action_sleep_spec.rb +9 -9
- data/spec/monkey_action_type_spec.rb +7 -7
- data/spec/monkey_action_wake_spec.rb +5 -5
- data/spec/monkey_factory_spec.rb +3 -11
- data/spec/monkey_keyboard_en_us_spec.rb +4 -7
- data/spec/monkey_manager_spec.rb +1 -1
- data/spec/monkey_service_spec.rb +11 -11
- data/spec/monkey_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples.rb +9 -9
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fdf0a5f0ea4f5c0f273c39861ecba684ce0946e7d79e3614b02b21a31f9297d
|
4
|
+
data.tar.gz: 7fb57980b14f6997f3dbc0f3318098e8a88d378643d14f8082462169d9557c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d7d05635c56b4576cc2661cfd57926d421dda2282002f0b85c4769e5b6f0d49afbf61cd245f85be427d9f1b348d8ea651bfd4cf50319a7bb2192f8dabe0cda
|
7
|
+
data.tar.gz: 765db556503e17d6a1d048cb21727e614a8902cd01e1ca0484d1871478d83e3affc56b156a3b81c99f303bd08fbc1eb9d75cb71479b28bf3298a5e5c1009b4d7
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0.1
|
7
|
+
NewCops: enable
|
8
|
+
Exclude:
|
9
|
+
- '.git/**/*'
|
10
|
+
- '.idea/**/*'
|
11
|
+
- 'init/*'
|
12
|
+
- 'Rakefile'
|
13
|
+
- '*.gemspec'
|
14
|
+
# - 'spec/**/*'
|
15
|
+
- 'vendor/**/*'
|
16
|
+
- 'scratch*.rb'
|
17
|
+
- 'snippets*.rb'
|
18
|
+
|
19
|
+
# Align the elements of a hash literal if they span more than one line.
|
20
|
+
Layout/HashAlignment:
|
21
|
+
EnforcedLastArgumentHashStyle: always_ignore
|
22
|
+
|
23
|
+
# Alignment of parameters in multi-line method definition.
|
24
|
+
# The `with_fixed_indentation` style aligns the following lines with one
|
25
|
+
# level of indentation relative to the start of the line with the method
|
26
|
+
# definition.
|
27
|
+
#
|
28
|
+
# def my_method(a,
|
29
|
+
# b)
|
30
|
+
Layout/ParameterAlignment:
|
31
|
+
EnforcedStyle: with_fixed_indentation
|
32
|
+
|
33
|
+
# Alignment of parameters in multi-line method call.
|
34
|
+
# The `with_fixed_indentation` style aligns the following lines with one
|
35
|
+
# level of indentation relative to the start of the line with the method call.
|
36
|
+
#
|
37
|
+
# my_method(a,
|
38
|
+
# b)
|
39
|
+
Layout/ArgumentAlignment:
|
40
|
+
EnforcedStyle: with_fixed_indentation
|
41
|
+
|
42
|
+
# a = case n
|
43
|
+
# when 0
|
44
|
+
# x * 2
|
45
|
+
# else
|
46
|
+
# y / 3
|
47
|
+
# end
|
48
|
+
Layout/CaseIndentation:
|
49
|
+
EnforcedStyle: end
|
50
|
+
|
51
|
+
# Enforces a configured order of definitions within a class body
|
52
|
+
Layout/ClassStructure:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
# Align `end` with the matching keyword or starting expression except for
|
56
|
+
# assignments, where it should be aligned with the LHS.
|
57
|
+
Layout/EndAlignment:
|
58
|
+
EnforcedStyleAlignWith: variable
|
59
|
+
AutoCorrect: true
|
60
|
+
|
61
|
+
# The `consistent` style enforces that the first element in an array
|
62
|
+
# literal where the opening bracket and the first element are on
|
63
|
+
# seprate lines is indented the same as an array literal which is not
|
64
|
+
# defined inside a method call.
|
65
|
+
Layout/FirstArrayElementIndentation:
|
66
|
+
EnforcedStyle: consistent
|
67
|
+
|
68
|
+
# The `consistent` style enforces that the first key in a hash
|
69
|
+
# literal where the opening brace and the first key are on
|
70
|
+
# seprate lines is indented the same as a hash literal which is not
|
71
|
+
# defined inside a method call.
|
72
|
+
Layout/FirstHashElementIndentation:
|
73
|
+
EnforcedStyle: consistent
|
74
|
+
|
75
|
+
# Indent multi-line methods instead of aligning with periods
|
76
|
+
Layout/MultilineMethodCallIndentation:
|
77
|
+
EnforcedStyle: indented
|
78
|
+
|
79
|
+
# Allow `debug` in tasks for now
|
80
|
+
Lint/Debugger:
|
81
|
+
Exclude:
|
82
|
+
- 'RakeFile'
|
83
|
+
|
84
|
+
# A calculated magnitude based on number of assignments, branches, and
|
85
|
+
# conditions.
|
86
|
+
# NOTE: This is temporarily disabled until we can eliminate existing Rubocop
|
87
|
+
# complaints
|
88
|
+
Metrics/AbcSize:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
# Avoid long blocks with many lines.
|
92
|
+
Metrics/BlockLength:
|
93
|
+
Exclude:
|
94
|
+
- 'RakeFile'
|
95
|
+
- 'db/seeds.rb'
|
96
|
+
- 'spec/**/*.rb'
|
97
|
+
|
98
|
+
# Avoid classes longer than 100 lines of code.
|
99
|
+
# NOTE: This is temporarily disabled until we can eliminate existing Rubocop
|
100
|
+
# complaints
|
101
|
+
Metrics/ClassLength:
|
102
|
+
Max: 200
|
103
|
+
Exclude:
|
104
|
+
- 'spec/**/*.rb'
|
105
|
+
|
106
|
+
# A complexity metric that is strongly correlated to the number of test cases
|
107
|
+
# needed to validate a method.
|
108
|
+
Metrics/CyclomaticComplexity:
|
109
|
+
Max: 9
|
110
|
+
|
111
|
+
# Limit lines to 80 characters
|
112
|
+
Layout/LineLength:
|
113
|
+
Exclude:
|
114
|
+
- 'RakeFile'
|
115
|
+
- 'spec/**/*.rb'
|
116
|
+
|
117
|
+
# Avoid methods longer than 15 lines of code.
|
118
|
+
Metrics/MethodLength:
|
119
|
+
Max: 20
|
120
|
+
AllowedMethods:
|
121
|
+
- swagger_path
|
122
|
+
- operation
|
123
|
+
|
124
|
+
|
125
|
+
# A complexity metric geared towards measuring complexity for a human reader.
|
126
|
+
Metrics/PerceivedComplexity:
|
127
|
+
Max: 10
|
128
|
+
|
129
|
+
NestedGroups:
|
130
|
+
Max: 4
|
131
|
+
|
132
|
+
# Naming/FileName:
|
133
|
+
# Exclude:
|
134
|
+
# - 'lib/file.rb'
|
135
|
+
|
136
|
+
# Allow `downcase == ` instead of forcing `casecmp`
|
137
|
+
Performance/Casecmp:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
# Require children definitions to be nested or compact in classes and modules
|
141
|
+
Style/ClassAndModuleChildren:
|
142
|
+
Enabled: false
|
143
|
+
|
144
|
+
# Document classes and non-namespace modules.
|
145
|
+
# (Disabled for now, may revisit later)
|
146
|
+
Style/Documentation:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
# Checks the formatting of empty method definitions.
|
150
|
+
Style/EmptyMethod:
|
151
|
+
EnforcedStyle: expanded
|
152
|
+
|
153
|
+
# Add the frozen_string_literal comment to the top of files to help transition
|
154
|
+
# to frozen string literals by default.
|
155
|
+
Style/FrozenStringLiteralComment:
|
156
|
+
EnforcedStyle: always
|
157
|
+
|
158
|
+
# Check for conditionals that can be replaced with guard clauses
|
159
|
+
Style/GuardClause:
|
160
|
+
Enabled: false
|
161
|
+
|
162
|
+
Style/MixinUsage:
|
163
|
+
Exclude:
|
164
|
+
- 'RakeFile'
|
165
|
+
|
166
|
+
# Avoid multi-line method signatures.
|
167
|
+
Style/MultilineMethodSignature:
|
168
|
+
Enabled: true
|
169
|
+
|
170
|
+
# Don't use option hashes when you can use keyword arguments.
|
171
|
+
Style/OptionHash:
|
172
|
+
Enabled: true
|
173
|
+
|
174
|
+
# Use return instead of return nil.
|
175
|
+
Style/ReturnNil:
|
176
|
+
Enabled: true
|
177
|
+
|
178
|
+
# Allow code like `return x, y` as it's occasionally handy.
|
179
|
+
Style/RedundantReturn:
|
180
|
+
AllowMultipleReturnValues: true
|
181
|
+
|
182
|
+
# Prefer symbols instead of strings as hash keys.
|
183
|
+
Style/StringHashKeys:
|
184
|
+
Enabled: true
|
185
|
+
|
186
|
+
# Checks if configured preferred methods are used over non-preferred.
|
187
|
+
Style/StringMethods:
|
188
|
+
Enabled: true
|
189
|
+
|
190
|
+
# Checks for use of parentheses around ternary conditions.
|
191
|
+
Style/TernaryParentheses:
|
192
|
+
EnforcedStyle: require_parentheses_when_complex
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
### Version 2.0.1
|
2
|
+
- Update ruby gems.
|
3
|
+
- Various refactors.
|
4
|
+
|
1
5
|
### Version 2.0.0
|
2
|
-
|
3
|
-
|
6
|
+
- Use LittleWeasel gem for dictionary.
|
7
|
+
- Gem update to patch CVEs.
|
8
|
+
|
4
9
|
### Version 1.1.0
|
5
|
-
|
6
|
-
|
10
|
+
- Made some changes to the sample rake task $ bundle exec rake engine:run
|
11
|
+
- Added this CHANGELOG.md file
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
MonkeyEngine (2.0.
|
4
|
+
MonkeyEngine (2.0.1)
|
5
5
|
LittleWeasel (~> 5.0, >= 5.0.3)
|
6
6
|
ProtectedConstructor (~> 2.0, >= 2.0.3)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
LittleWeasel (5.0.
|
11
|
+
LittleWeasel (5.0.6)
|
12
12
|
activesupport (~> 6.1, >= 6.1.3.2)
|
13
|
-
ProtectedConstructor (2.1.
|
14
|
-
activesupport (6.1.7.
|
13
|
+
ProtectedConstructor (2.1.4)
|
14
|
+
activesupport (6.1.7.6)
|
15
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
16
|
i18n (>= 1.6, < 2)
|
17
17
|
minitest (>= 5.1)
|
@@ -22,10 +22,10 @@ GEM
|
|
22
22
|
colorize (0.8.1)
|
23
23
|
concurrent-ruby (1.2.2)
|
24
24
|
diff-lcs (1.5.0)
|
25
|
-
i18n (1.
|
25
|
+
i18n (1.14.1)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
method_source (1.0.0)
|
28
|
-
minitest (5.
|
28
|
+
minitest (5.19.0)
|
29
29
|
pry (0.14.2)
|
30
30
|
coderay (~> 1.1)
|
31
31
|
method_source (~> 1.0)
|
@@ -38,24 +38,23 @@ GEM
|
|
38
38
|
rspec-core (~> 3.12.0)
|
39
39
|
rspec-expectations (~> 3.12.0)
|
40
40
|
rspec-mocks (~> 3.12.0)
|
41
|
-
rspec-core (3.12.
|
41
|
+
rspec-core (3.12.2)
|
42
42
|
rspec-support (~> 3.12.0)
|
43
|
-
rspec-expectations (3.12.
|
43
|
+
rspec-expectations (3.12.3)
|
44
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
45
|
rspec-support (~> 3.12.0)
|
46
|
-
rspec-mocks (3.12.
|
46
|
+
rspec-mocks (3.12.6)
|
47
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
48
|
rspec-support (~> 3.12.0)
|
49
|
-
rspec-support (3.12.
|
49
|
+
rspec-support (3.12.1)
|
50
50
|
tzinfo (2.0.6)
|
51
51
|
concurrent-ruby (~> 1.0)
|
52
|
-
|
53
|
-
|
54
|
-
webrick (~> 1.7.0)
|
55
|
-
zeitwerk (2.6.7)
|
52
|
+
yard (0.9.34)
|
53
|
+
zeitwerk (2.6.11)
|
56
54
|
|
57
55
|
PLATFORMS
|
58
56
|
x86_64-darwin-19
|
57
|
+
x86_64-darwin-21
|
59
58
|
|
60
59
|
DEPENDENCIES
|
61
60
|
MonkeyEngine!
|
@@ -68,4 +67,4 @@ DEPENDENCIES
|
|
68
67
|
yard (~> 0.9.28)
|
69
68
|
|
70
69
|
BUNDLED WITH
|
71
|
-
2.3.
|
70
|
+
2.3.22
|
data/lib/Action/action.rb
CHANGED
data/lib/Monkey/monkey.rb
CHANGED
@@ -31,7 +31,6 @@ class Monkey
|
|
31
31
|
def initialize(monkey_symbol)
|
32
32
|
@monkey_symbol = monkey_symbol
|
33
33
|
@monkey_service = MonkeyEngine::MonkeyService.instance
|
34
|
-
self
|
35
34
|
end
|
36
35
|
|
37
36
|
public
|
@@ -76,7 +75,7 @@ class Monkey
|
|
76
75
|
def start
|
77
76
|
if alive?
|
78
77
|
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
79
|
-
|
78
|
+
"The monkey [#{@monkey_symbol}] thread is already started"
|
80
79
|
end
|
81
80
|
|
82
81
|
initialize_thread
|
@@ -13,8 +13,6 @@ class MonkeyActionDead < MonkeyAction
|
|
13
13
|
super monkey, true, WEIGHT
|
14
14
|
|
15
15
|
validate
|
16
|
-
|
17
|
-
self
|
18
16
|
end
|
19
17
|
|
20
18
|
protected
|
@@ -22,7 +20,7 @@ class MonkeyActionDead < MonkeyAction
|
|
22
20
|
def validate
|
23
21
|
super
|
24
22
|
|
25
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"
|
23
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
26
24
|
unless VALID_VALUES.include?(@value)
|
27
25
|
end
|
28
26
|
end
|
@@ -18,8 +18,6 @@ class MonkeyActionEat < MonkeyTimedAction
|
|
18
18
|
@action_time_of_completion = @action_time + (value * 60)
|
19
19
|
|
20
20
|
validate
|
21
|
-
|
22
|
-
self
|
23
21
|
end
|
24
22
|
|
25
23
|
protected
|
@@ -27,7 +25,7 @@ class MonkeyActionEat < MonkeyTimedAction
|
|
27
25
|
def validate
|
28
26
|
super
|
29
27
|
|
30
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"
|
28
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
29
|
unless VALID_VALUES.include?(@value)
|
32
30
|
end
|
33
31
|
end
|
@@ -18,8 +18,6 @@ class MonkeyActionPause < MonkeyTimedAction
|
|
18
18
|
@action_time_of_completion = @action_time + value
|
19
19
|
|
20
20
|
validate
|
21
|
-
|
22
|
-
self
|
23
21
|
end
|
24
22
|
|
25
23
|
protected
|
@@ -27,7 +25,7 @@ class MonkeyActionPause < MonkeyTimedAction
|
|
27
25
|
def validate
|
28
26
|
super
|
29
27
|
|
30
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"
|
28
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
29
|
unless VALID_VALUES.include?(@value)
|
32
30
|
end
|
33
31
|
end
|
@@ -18,8 +18,6 @@ class MonkeyActionSleep < MonkeyTimedAction
|
|
18
18
|
@action_time_of_completion = @action_time + (value * (60 * 60))
|
19
19
|
|
20
20
|
validate
|
21
|
-
|
22
|
-
self
|
23
21
|
end
|
24
22
|
|
25
23
|
protected
|
@@ -27,7 +25,7 @@ class MonkeyActionSleep < MonkeyTimedAction
|
|
27
25
|
def validate
|
28
26
|
super
|
29
27
|
|
30
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"
|
28
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
29
|
unless VALID_VALUES.include?(@value)
|
32
30
|
end
|
33
31
|
end
|
@@ -11,12 +11,12 @@ class MonkeyActionType < MonkeyAction
|
|
11
11
|
WEIGHT = 5.0
|
12
12
|
|
13
13
|
def initialize(monkey, keyboard_input)
|
14
|
-
raise MonkeyEngine::Exceptions::NilArgumentException, "keyboard_input '#{keyboard_input}' cannot be nil"
|
14
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "keyboard_input '#{keyboard_input}' cannot be nil" \
|
15
15
|
if keyboard_input.nil?
|
16
16
|
|
17
17
|
unless keyboard_input.is_a?(KeyboardInput)
|
18
18
|
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
|
19
|
-
|
19
|
+
"keyboard_input '#{keyboard_input}' is not a valid argument type"
|
20
20
|
end
|
21
21
|
|
22
22
|
@keyboard_input = keyboard_input
|
@@ -24,22 +24,20 @@ class MonkeyActionType < MonkeyAction
|
|
24
24
|
super monkey, @keyboard_input.input, WEIGHT
|
25
25
|
|
26
26
|
validate
|
27
|
-
|
28
|
-
self
|
29
27
|
end
|
30
28
|
|
31
29
|
protected
|
32
30
|
|
33
31
|
def validate
|
34
|
-
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil"
|
32
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
|
35
33
|
if @value.nil?
|
36
34
|
|
37
35
|
unless @value.is_a?(Array)
|
38
36
|
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
|
39
|
-
|
37
|
+
"Value '#{value}' is not a valid argument type (#{value.class.name})"
|
40
38
|
end
|
41
39
|
|
42
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' cannot be empty"
|
40
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' cannot be empty" \
|
43
41
|
if @value.empty?
|
44
42
|
end
|
45
43
|
end
|
@@ -13,8 +13,6 @@ class MonkeyActionWake < MonkeyAction
|
|
13
13
|
super monkey, true, WEIGHT
|
14
14
|
|
15
15
|
validate
|
16
|
-
|
17
|
-
self
|
18
16
|
end
|
19
17
|
|
20
18
|
protected
|
@@ -22,7 +20,7 @@ class MonkeyActionWake < MonkeyAction
|
|
22
20
|
def validate
|
23
21
|
super
|
24
22
|
|
25
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"
|
23
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
26
24
|
unless VALID_VALUES.include?(@value)
|
27
25
|
end
|
28
26
|
end
|
@@ -13,17 +13,15 @@ class MonkeyTimedAction < MonkeyAction
|
|
13
13
|
@action_time_of_completion = nil
|
14
14
|
|
15
15
|
validate
|
16
|
-
|
17
|
-
self
|
18
16
|
end
|
19
17
|
|
20
18
|
protected
|
21
19
|
|
22
20
|
def validate
|
23
|
-
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil"
|
21
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
|
24
22
|
if @value.nil?
|
25
23
|
|
26
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, "Value '#{value}' is not a valid argument type"
|
24
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, "Value '#{value}' is not a valid argument type" \
|
27
25
|
unless @value.is_a?(Integer)
|
28
26
|
end
|
29
27
|
end
|
@@ -17,7 +17,7 @@ class ActionRules
|
|
17
17
|
def get_next_action(monkey)
|
18
18
|
unless monkey.action.nil? || monkey.action.action_completed?
|
19
19
|
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
20
|
-
|
20
|
+
"The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action"
|
21
21
|
end
|
22
22
|
|
23
23
|
# current_action = monkey.action
|
@@ -13,12 +13,6 @@ module MonkeyEngine
|
|
13
13
|
include Singleton
|
14
14
|
include Observable
|
15
15
|
|
16
|
-
private
|
17
|
-
|
18
|
-
def initialize; end
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
16
|
# Evaluates whether or not the action is completed.
|
23
17
|
def action_eval!(action)
|
24
18
|
ActionRules.instance.action_eval! action
|
@@ -27,7 +21,7 @@ module MonkeyEngine
|
|
27
21
|
def do_action(action)
|
28
22
|
if action.action_completed?
|
29
23
|
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
30
|
-
|
24
|
+
"The action [#{action.class.name}] for Monkey [#{action.monkey.monkey_symbol}] is already completed"
|
31
25
|
end
|
32
26
|
|
33
27
|
do_action_type(action) if action.is_a? MonkeyActionType
|
@@ -47,7 +41,7 @@ module MonkeyEngine
|
|
47
41
|
def new_action(monkey)
|
48
42
|
unless monkey.action.nil? || monkey.action.action_completed?
|
49
43
|
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
50
|
-
|
44
|
+
"The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling new_action"
|
51
45
|
end
|
52
46
|
|
53
47
|
ActionRules.instance.get_next_action monkey
|
data/lib/MonkeyEngine/version.rb
CHANGED
@@ -6,6 +6,15 @@ require_relative 'keyboard_char'
|
|
6
6
|
class KeyboardKey
|
7
7
|
attr_reader :keyboard_char, :keyboard_shift_char, :keyboard_key_section, :keyboard_key_weight
|
8
8
|
|
9
|
+
def self.make_key(char, shift_char, keyboard_key_section, keyboard_key_weight)
|
10
|
+
# TODO: Check keyboard_key_section is :left or :right
|
11
|
+
|
12
|
+
keyboard_char = KeyboardChar.new char
|
13
|
+
keyboard_shift_char = KeyboardChar.new shift_char
|
14
|
+
|
15
|
+
KeyboardKey.new keyboard_char, keyboard_shift_char, keyboard_key_section, keyboard_key_weight
|
16
|
+
end
|
17
|
+
|
9
18
|
def initialize(keyboard_char, keyboard_shift_char, keyboard_key_section, keyboard_key_weight)
|
10
19
|
# TODO: Check keyboard_char is_a? KeyboardChar
|
11
20
|
# TODO: Check keyboard_shift_char is_a? KeyboardChar
|
@@ -16,13 +25,4 @@ class KeyboardKey
|
|
16
25
|
@keyboard_key_section = keyboard_key_section
|
17
26
|
@keyboard_key_weight = keyboard_key_weight
|
18
27
|
end
|
19
|
-
|
20
|
-
def self.make_key(char, shift_char, keyboard_key_section, keyboard_key_weight)
|
21
|
-
# TODO: Check keyboard_key_section is :left or :right
|
22
|
-
|
23
|
-
keyboard_char = KeyboardChar.new char
|
24
|
-
keyboard_shift_char = KeyboardChar.new shift_char
|
25
|
-
|
26
|
-
KeyboardKey.new keyboard_char, keyboard_shift_char, keyboard_key_section, keyboard_key_weight
|
27
|
-
end
|
28
28
|
end
|
@@ -10,7 +10,7 @@ class KeyboardKeyEvaluator
|
|
10
10
|
@shift_on = !@shift_on if keyboard_key.keyboard_char.char == :shift
|
11
11
|
@caps_on = !@shift_on if keyboard_key.keyboard_char.char == :caps
|
12
12
|
|
13
|
-
return
|
13
|
+
return if keyboard_key.keyboard_char.char.is_a? Symbol
|
14
14
|
|
15
15
|
return keyboard_key.keyboard_shift_char.char if @shift_on
|
16
16
|
|
@@ -16,7 +16,7 @@ module MonkeyEngine
|
|
16
16
|
attr_reader :keys, :left_keys, :right_keys
|
17
17
|
|
18
18
|
def initialize
|
19
|
-
LittleWeasel.configure
|
19
|
+
LittleWeasel.configure { |config| }
|
20
20
|
|
21
21
|
@keys = [
|
22
22
|
# Row 1 of 5
|
@@ -124,7 +124,7 @@ module MonkeyEngine
|
|
124
124
|
# Take the keys until we hit a key that terminates a word...
|
125
125
|
keyboard_input.input = keys.take_while do |key|
|
126
126
|
!keyboard_char_ends_word?(key.keyboard_char.char)
|
127
|
-
end.
|
127
|
+
end.filter_map { |key| keyboard_key_evaluator.get_char(key) }
|
128
128
|
|
129
129
|
# Keep going until we get something...
|
130
130
|
keyboard_input = get_keyboard_input if keyboard_input.input.empty?
|
@@ -82,15 +82,15 @@ module MonkeyEngine
|
|
82
82
|
# @raise [MonkeyEngine::Exceptions::InvalidArgumentTypeException] if parameter monkey is not a Monkey, Symbol, or String object.
|
83
83
|
#
|
84
84
|
def get(monkey)
|
85
|
-
return
|
85
|
+
return if @monkeys.empty?
|
86
86
|
|
87
87
|
# TODO: This seems inefficient.
|
88
|
-
return @monkeys.
|
89
|
-
return @monkeys.
|
90
|
-
return @monkeys.
|
88
|
+
return @monkeys.find { |m| m.monkey_symbol == monkey } if monkey.is_a? Symbol
|
89
|
+
return @monkeys.find { |m| m.monkey_symbol == monkey.to_sym } if monkey.is_a? String
|
90
|
+
return @monkeys.find { |m| m.monkey_symbol == monkey.monkey_symbol } if monkey.is_a? Monkey
|
91
91
|
|
92
92
|
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
|
93
|
-
|
93
|
+
"Parameter 'monkey' is not a Symbol, String or Monkey object"
|
94
94
|
end
|
95
95
|
|
96
96
|
# Returns a duplicate Array of Monkey objects managed by this MonkeyManager.
|
data/lib/tasks/engine.rb
CHANGED
@@ -9,7 +9,7 @@ require 'LittleWeasel'
|
|
9
9
|
require File.expand_path('../MonkeyFactory', __dir__)
|
10
10
|
require File.expand_path('../MonkeyEngine', __dir__)
|
11
11
|
|
12
|
-
LittleWeasel.configure
|
12
|
+
LittleWeasel.configure { |config| }
|
13
13
|
|
14
14
|
module Runner
|
15
15
|
class MonkeyRun
|
@@ -26,8 +26,6 @@ module Runner
|
|
26
26
|
go
|
27
27
|
sleep @runtime
|
28
28
|
end
|
29
|
-
|
30
|
-
self
|
31
29
|
end
|
32
30
|
|
33
31
|
def go
|
@@ -90,17 +88,23 @@ namespace :engine do
|
|
90
88
|
word = monkey_word[0]
|
91
89
|
times = monkey_word[1]
|
92
90
|
if word.length > 1
|
93
|
-
puts "#{word_index}. Monkey [#{monkey.capitalize}] typed [#{word.capitalize}] [#{times}] time(s)
|
91
|
+
puts "#{word_index}. Monkey [#{monkey.capitalize}] typed [#{word.capitalize}] [#{times}] time(s) " \
|
92
|
+
"<=== #{word.length}-letter word!".colorize(
|
93
|
+
color: :green, mode: :bold
|
94
|
+
)
|
94
95
|
else
|
95
|
-
puts "#{word_index}. Monkey [#{monkey.capitalize}] typed [#{word.capitalize}] [#{times}] time(s)"
|
96
|
+
puts "#{word_index}. Monkey [#{monkey.capitalize}] typed [#{word.capitalize}] [#{times}] time(s)"
|
97
|
+
.colorize(color: :green)
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
99
|
-
total_valid_words_count = runner.monkey_words.inject(0)
|
101
|
+
total_valid_words_count = runner.monkey_words.inject(0) do |sum, monkey_word_info|
|
102
|
+
sum + monkey_word_info[1].keys.count
|
103
|
+
end
|
100
104
|
|
101
105
|
puts '-----------------------------------------'
|
102
106
|
puts "Total valid words: #{total_valid_words_count}"
|
103
|
-
puts 'These monkeys can type!' if total_valid_words_count
|
107
|
+
puts 'These monkeys can type!' if total_valid_words_count.positive?
|
104
108
|
puts 'Done.'
|
105
109
|
puts
|
106
110
|
puts
|