MonkeyEngine 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +19 -16
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +192 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +10 -2
  7. data/Gemfile +3 -1
  8. data/Gemfile.lock +70 -0
  9. data/Rakefile +3 -2
  10. data/dictionaries/en-US.txt +466554 -0
  11. data/lib/Action/action.rb +5 -6
  12. data/lib/Monkey/monkey.rb +17 -13
  13. data/lib/Monkey.rb +3 -1
  14. data/lib/MonkeyAction/monkey_action.rb +3 -3
  15. data/lib/MonkeyAction/monkey_action_dead.rb +8 -8
  16. data/lib/MonkeyAction/monkey_action_eat.rb +6 -6
  17. data/lib/MonkeyAction/monkey_action_pause.rb +6 -7
  18. data/lib/MonkeyAction/monkey_action_sleep.rb +6 -6
  19. data/lib/MonkeyAction/monkey_action_type.rb +15 -12
  20. data/lib/MonkeyAction/monkey_action_wake.rb +8 -8
  21. data/lib/MonkeyAction/monkey_timed_action.rb +6 -6
  22. data/lib/MonkeyActions.rb +2 -0
  23. data/lib/MonkeyEngine/action_rules.rb +20 -18
  24. data/lib/MonkeyEngine/exceptions.rb +7 -7
  25. data/lib/MonkeyEngine/monkey_engine.rb +11 -14
  26. data/lib/MonkeyEngine/version.rb +3 -1
  27. data/lib/MonkeyEngine.rb +3 -1
  28. data/lib/MonkeyFactory/monkey_factory.rb +3 -4
  29. data/lib/MonkeyFactory.rb +3 -1
  30. data/lib/MonkeyKeyboard/keyboard_char.rb +3 -3
  31. data/lib/MonkeyKeyboard/keyboard_input.rb +4 -3
  32. data/lib/MonkeyKeyboard/keyboard_key.rb +12 -10
  33. data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +6 -8
  34. data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +100 -80
  35. data/lib/MonkeyKeyboardEnUs.rb +3 -1
  36. data/lib/MonkeyManager/monkey_manager.rb +17 -15
  37. data/lib/MonkeyManager.rb +3 -1
  38. data/lib/MonkeyService/monkey_service.rb +8 -9
  39. data/lib/MonkeyService.rb +3 -1
  40. data/lib/tasks/engine.rb +63 -54
  41. data/monkeyengine.gemspec +26 -20
  42. data/spec/action_rules_spec.rb +17 -23
  43. data/spec/engine_spec.rb +15 -20
  44. data/spec/keyboard_char_spec.rb +4 -5
  45. data/spec/keyboard_key_spec.rb +8 -9
  46. data/spec/monkey_action_eat_spec.rb +17 -18
  47. data/spec/monkey_action_pause_spec.rb +19 -20
  48. data/spec/monkey_action_sleep_spec.rb +19 -20
  49. data/spec/monkey_action_type_spec.rb +25 -24
  50. data/spec/monkey_action_wake_spec.rb +10 -11
  51. data/spec/monkey_factory_spec.rb +7 -15
  52. data/spec/monkey_keyboard_en_us_spec.rb +10 -19
  53. data/spec/monkey_manager_spec.rb +3 -2
  54. data/spec/monkey_service_spec.rb +26 -29
  55. data/spec/monkey_spec.rb +3 -2
  56. data/spec/{spec_helpers.rb → spec_helper.rb} +7 -5
  57. data/spec/support/shared_examples.rb +16 -16
  58. metadata +69 -55
  59. data/.idea/.name +0 -1
  60. data/.idea/.rakeTasks +0 -7
  61. data/.idea/MonkeyEngine.iml +0 -133
  62. data/.idea/codeStyleSettings.xml +0 -13
  63. data/.idea/encodings.xml +0 -5
  64. data/.idea/misc.xml +0 -5
  65. data/.idea/modules.xml +0 -9
  66. data/.idea/runConfigurations/All_specs_in_test__MonkeyEngine.xml +0 -38
  67. data/.idea/runConfigurations/IRB_console.xml +0 -25
  68. data/.idea/runConfigurations/Start_Yard_Server.xml +0 -26
  69. data/.idea/runConfigurations/monkey_run.xml +0 -26
  70. data/.idea/scopes/scope_settings.xml +0 -5
  71. data/.idea/vcs.xml +0 -7
  72. data/.idea/workspace.xml +0 -886
data/lib/Action/action.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  # Defines a base action.
@@ -10,20 +12,17 @@ class Action
10
12
  @weight = weight
11
13
  @action_time = Time.now
12
14
  @action_completed = false
13
-
14
- self
15
15
  end
16
16
 
17
17
  def action_completed?
18
18
  @action_completed
19
19
  end
20
20
 
21
- def action_completed=(value)
22
- @action_completed = value
23
- end
21
+ attr_writer :action_completed
24
22
 
25
23
  protected
24
+
26
25
  def validate
27
26
  # throw if invalid state
28
27
  end
29
- end
28
+ end
data/lib/Monkey/monkey.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'thread'
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'MonkeyActions'
4
4
  require 'MonkeyService'
@@ -27,10 +27,10 @@ class Monkey
27
27
  attr_reader :monkey_symbol, :action
28
28
 
29
29
  protected
30
+
30
31
  def initialize(monkey_symbol)
31
32
  @monkey_symbol = monkey_symbol
32
33
  @monkey_service = MonkeyEngine::MonkeyService.instance
33
- self
34
34
  end
35
35
 
36
36
  public
@@ -43,6 +43,7 @@ class Monkey
43
43
  #
44
44
  def alive?
45
45
  return false if @thread.nil?
46
+
46
47
  @thread.alive?
47
48
  end
48
49
 
@@ -52,6 +53,7 @@ class Monkey
52
53
  #
53
54
  def current_action
54
55
  return MonkeyActionDead.new(self) unless alive?
56
+
55
57
  @action
56
58
  end
57
59
 
@@ -71,8 +73,11 @@ class Monkey
71
73
  # @return [Monkey, self]
72
74
  #
73
75
  def start
74
- raise MonkeyEngine::Exceptions::InvalidOperationException.new "The monkey [#{@monkey_symbol}] thread is already started" \
75
- if alive?
76
+ if alive?
77
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
78
+ "The monkey [#{@monkey_symbol}] thread is already started"
79
+ end
80
+
76
81
  initialize_thread
77
82
  self
78
83
  end
@@ -81,28 +86,27 @@ class Monkey
81
86
  #
82
87
  # @return [Thread]
83
88
  #
84
- def thread
85
- @thread
86
- end
89
+ attr_reader :thread
87
90
 
88
91
  protected
92
+
89
93
  def initialize_thread
90
- @sleep_time = 1.0/250.0
94
+ @sleep_time = 1.0 / 250.0
91
95
  @kill_thread = false
92
96
 
93
- @thread = Thread.new {
97
+ @thread = Thread.new do
94
98
  monkey_do
95
- }
99
+ end
96
100
 
97
- #@thread.freeze
101
+ # @thread.freeze
98
102
  @thread.abort_on_exception = true
99
103
  end
100
104
 
101
105
  def monkey_do
102
- until @kill_thread do
106
+ until @kill_thread
103
107
  @action = @monkey_service.new_action(self) if @action.nil? || @action.action_completed?
104
108
  @monkey_service.monkey_do @action unless @monkey_service.action_eval! @action
105
109
  sleep(@sleep_time)
106
110
  end
107
111
  end
108
- end
112
+ end
data/lib/Monkey.rb CHANGED
@@ -1 +1,3 @@
1
- require_relative 'Monkey/monkey'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'Monkey/monkey'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'Action/action'
2
4
 
3
5
  # MonkeyAction.
@@ -8,7 +10,5 @@ class MonkeyAction < Action
8
10
  super value, weight
9
11
 
10
12
  @monkey = monkey
11
-
12
- self
13
13
  end
14
- end
14
+ end
@@ -1,26 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'monkey_action'
2
4
  require 'MonkeyEngine/exceptions'
3
5
 
4
6
  # Monkey action: dead (as in not alive)
5
7
  # The monkey has been killed - the thread is not running.
6
8
  class MonkeyActionDead < MonkeyAction
7
-
8
9
  WEIGHT = 100.0
9
- VALID_VALUES = [ true ]
10
+ VALID_VALUES = [true].freeze
10
11
 
11
12
  def initialize(monkey)
12
- super monkey, true , WEIGHT
13
+ super monkey, true, WEIGHT
13
14
 
14
15
  validate
15
-
16
- self
17
16
  end
18
17
 
19
18
  protected
19
+
20
20
  def validate
21
21
  super
22
22
 
23
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
24
- if !VALID_VALUES.include?(@value)
23
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
24
+ unless VALID_VALUES.include?(@value)
25
25
  end
26
- end
26
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  require_relative 'monkey_action'
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
7
9
  # Monkey action: eat (as in banana)
8
10
  # The monkey is eating.
9
11
  class MonkeyActionEat < MonkeyTimedAction
10
-
11
12
  WEIGHT = 2.0
12
13
  VALID_VALUES = (30..60) # 30 through 60 minutes
13
14
 
@@ -17,15 +18,14 @@ class MonkeyActionEat < MonkeyTimedAction
17
18
  @action_time_of_completion = @action_time + (value * 60)
18
19
 
19
20
  validate
20
-
21
- self
22
21
  end
23
22
 
24
23
  protected
24
+
25
25
  def validate
26
26
  super
27
27
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
28
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
29
+ unless VALID_VALUES.include?(@value)
30
30
  end
31
- end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  require_relative 'monkey_action'
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
7
9
  # Monkey action: pause (as in take a break)
8
10
  # The monkey paused, usually from typing.
9
11
  class MonkeyActionPause < MonkeyTimedAction
10
-
11
12
  WEIGHT = 2.0
12
13
  VALID_VALUES = (0..60) # Seconds (0 - 60 seconds)
13
14
 
@@ -17,16 +18,14 @@ class MonkeyActionPause < MonkeyTimedAction
17
18
  @action_time_of_completion = @action_time + value
18
19
 
19
20
  validate
20
-
21
- self
22
21
  end
23
22
 
24
23
  protected
24
+
25
25
  def validate
26
26
  super
27
27
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
28
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
29
+ unless VALID_VALUES.include?(@value)
30
30
  end
31
-
32
- end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  require_relative 'monkey_action'
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
7
9
  # Monkey action: sleep (as in take a snooze)
8
10
  # The monkey is a sleep.
9
11
  class MonkeyActionSleep < MonkeyTimedAction
10
-
11
12
  WEIGHT = 10.0
12
13
  VALID_VALUES = ((60 * 6)..(60 * 8)) # 6 through 8 hours
13
14
 
@@ -17,15 +18,14 @@ class MonkeyActionSleep < MonkeyTimedAction
17
18
  @action_time_of_completion = @action_time + (value * (60 * 60))
18
19
 
19
20
  validate
20
-
21
- self
22
21
  end
23
22
 
24
23
  protected
24
+
25
25
  def validate
26
26
  super
27
27
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
28
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
29
+ unless VALID_VALUES.include?(@value)
30
30
  end
31
- end
31
+ end
@@ -1,40 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'monkey_action'
2
4
  require 'MonkeyEngine/exceptions'
3
5
 
4
6
  # Monkey action: type (as in keyboard)
5
7
  # The monkey typed something on the keyboard.
6
8
  class MonkeyActionType < MonkeyAction
7
-
8
9
  attr_reader :keyboard_input
9
10
 
10
11
  WEIGHT = 5.0
11
12
 
12
13
  def initialize(monkey, keyboard_input)
13
- raise MonkeyEngine::Exceptions::NilArgumentException.new "keyboard_input '#{keyboard_input}' cannot be nil" \
14
+ raise MonkeyEngine::Exceptions::NilArgumentException, "keyboard_input '#{keyboard_input}' cannot be nil" \
14
15
  if keyboard_input.nil?
15
16
 
16
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "keyboard_input '#{keyboard_input}' is not a valid argument type" \
17
- unless keyboard_input.is_a?(KeyboardInput)
17
+ unless keyboard_input.is_a?(KeyboardInput)
18
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
19
+ "keyboard_input '#{keyboard_input}' is not a valid argument type"
20
+ end
18
21
 
19
22
  @keyboard_input = keyboard_input
20
23
 
21
24
  super monkey, @keyboard_input.input, WEIGHT
22
25
 
23
26
  validate
24
-
25
- self
26
27
  end
27
28
 
28
29
  protected
29
- def validate
30
30
 
31
- raise MonkeyEngine::Exceptions::NilArgumentException.new "Value '#{value}' cannot be nil" \
31
+ def validate
32
+ raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
32
33
  if @value.nil?
33
34
 
34
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "Value '#{value}' is not a valid argument type (#{value.class.name})" \
35
- unless @value.is_a?(Array)
35
+ unless @value.is_a?(Array)
36
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
37
+ "Value '#{value}' is not a valid argument type (#{value.class.name})"
38
+ end
36
39
 
37
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' cannot be empty" \
40
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' cannot be empty" \
38
41
  if @value.empty?
39
42
  end
40
- end
43
+ end
@@ -1,26 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'monkey_action'
2
4
  require 'MonkeyEngine/exceptions'
3
5
 
4
6
  # Monkey action: wake (as in from sleep)
5
7
  # The monkey has awakened from sleep.
6
8
  class MonkeyActionWake < MonkeyAction
7
-
8
9
  WEIGHT = 2.0
9
- VALID_VALUES = [ true ]
10
+ VALID_VALUES = [true].freeze
10
11
 
11
12
  def initialize(monkey)
12
- super monkey, true , WEIGHT
13
+ super monkey, true, WEIGHT
13
14
 
14
15
  validate
15
-
16
- self
17
16
  end
18
17
 
19
18
  protected
19
+
20
20
  def validate
21
21
  super
22
22
 
23
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
24
- if !VALID_VALUES.include?(@value)
23
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
24
+ unless VALID_VALUES.include?(@value)
25
25
  end
26
- end
26
+ end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'monkey_action'
2
4
  require 'MonkeyEngine/exceptions'
3
5
 
4
6
  # Monkey action: one that is timed based on an Integer.
5
7
  class MonkeyTimedAction < MonkeyAction
6
-
7
8
  attr_accessor :action_time_of_completion
8
9
 
9
10
  def initialize(monkey, value, weight)
@@ -12,16 +13,15 @@ class MonkeyTimedAction < MonkeyAction
12
13
  @action_time_of_completion = nil
13
14
 
14
15
  validate
15
-
16
- self
17
16
  end
18
17
 
19
18
  protected
19
+
20
20
  def validate
21
- raise MonkeyEngine::Exceptions::NilArgumentException.new "Value '#{value}' cannot be nil" \
21
+ raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
22
22
  if @value.nil?
23
23
 
24
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "Value '#{value}' is not a valid argument type" \
24
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, "Value '#{value}' is not a valid argument type" \
25
25
  unless @value.is_a?(Integer)
26
26
  end
27
- end
27
+ end
data/lib/MonkeyActions.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'MonkeyAction/monkey_action_dead'
2
4
  require_relative 'MonkeyAction/monkey_action_eat'
3
5
  require_relative 'MonkeyAction/monkey_action_pause'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
  require 'singleton'
3
5
 
@@ -8,14 +10,15 @@ require 'MonkeyKeyboardEnUs'
8
10
  class ActionRules
9
11
  include Singleton
10
12
 
11
- # Retrieves tne next action for the monkey
12
- #
13
- # @param [monkey] the monkey whose next action is to be retrieved
14
- # @return [MonkeyAction] the next monkey action
13
+ # Retrieves tne next action for the monkey
14
+ #
15
+ # @param [monkey] the monkey whose next action is to be retrieved
16
+ # @return [MonkeyAction] the next monkey action
15
17
  def get_next_action(monkey)
16
- raise MonkeyEngine::Exceptions::InvalidOperationException.new \
17
- "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action" \
18
- unless monkey.action.nil? || monkey.action.action_completed?
18
+ unless monkey.action.nil? || monkey.action.action_completed?
19
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
20
+ "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action"
21
+ end
19
22
 
20
23
  # current_action = monkey.action
21
24
 
@@ -34,15 +37,15 @@ class ActionRules
34
37
 
35
38
  keyboard_input = MonkeyEngine::MonkeyKeyboardEnUs.instance.get_keyboard_input
36
39
 
37
- return MonkeyActionType.new monkey, keyboard_input
40
+ MonkeyActionType.new monkey, keyboard_input
38
41
  end
39
42
 
40
43
  # Evaluates an action and sets it to completed if the criteria for completion is met.
41
44
  def action_eval!(action)
42
- raise MonkeyEngine::Exceptions::NilArgumentException.new "The [action] to be evaluated cannot be nil" \
45
+ raise MonkeyEngine::Exceptions::NilArgumentException, 'The [action] to be evaluated cannot be nil' \
43
46
  if action.nil?
44
47
 
45
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
48
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
46
49
  unless action.is_a? Action
47
50
 
48
51
  action_eval_eat(action) if action.is_a?(MonkeyActionEat)
@@ -61,28 +64,28 @@ class ActionRules
61
64
  # Action evaluation methods
62
65
 
63
66
  def action_eval_eat(action)
64
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
67
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
65
68
  unless action.is_a? MonkeyActionEat
66
69
 
67
70
  action_eval_timed_action action
68
71
  end
69
72
 
70
73
  def action_eval_pause(action)
71
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
74
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
72
75
  unless action.is_a? MonkeyActionPause
73
76
 
74
77
  action_eval_timed_action action
75
78
  end
76
79
 
77
80
  def action_eval_sleep(action)
78
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
81
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
79
82
  unless action.is_a? MonkeyActionSleep
80
83
 
81
84
  action_eval_timed_action action
82
85
  end
83
86
 
84
87
  def action_eval_type(action)
85
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
88
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
86
89
  unless action.is_a? MonkeyActionType
87
90
 
88
91
  # TODO: How do I evaluate this?
@@ -91,7 +94,7 @@ class ActionRules
91
94
  end
92
95
 
93
96
  def action_eval_wake(action)
94
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
97
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
95
98
  unless action.is_a? MonkeyActionWake
96
99
 
97
100
  action.action_completed = true
@@ -100,12 +103,11 @@ class ActionRules
100
103
  end
101
104
 
102
105
  def action_eval_timed_action(action)
103
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \
106
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
104
107
  unless action.is_a? MonkeyTimedAction
105
108
 
106
109
  action.action_completed = true if action.action_time_of_completion <= Time.now
107
110
 
108
111
  action
109
112
  end
110
-
111
- end
113
+ end
@@ -1,21 +1,21 @@
1
- require 'test/unit/assertions'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module MonkeyEngine
4
4
  module Exceptions
5
- class InvalidArgumentValueException < ArgumentError;
5
+ class InvalidArgumentValueException < ArgumentError
6
6
  end
7
7
 
8
- class InvalidArgumentTypeException < ArgumentError;
8
+ class InvalidArgumentTypeException < ArgumentError
9
9
  end
10
10
 
11
- class NilArgumentException < ArgumentError;
11
+ class NilArgumentException < ArgumentError
12
12
  end
13
13
 
14
14
  # The object must be unique.
15
- class UniqueObjectException < ArgumentError;
15
+ class UniqueObjectException < ArgumentError
16
16
  end
17
17
 
18
- class InvalidOperationException < ArgumentError;
18
+ class InvalidOperationException < ArgumentError
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'observer'
2
4
  require 'singleton'
3
5
  require 'time'
@@ -6,26 +8,21 @@ require 'MonkeyActions'
6
8
  require_relative 'action_rules'
7
9
 
8
10
  module MonkeyEngine
9
-
10
11
  # Assigns, executes and evaluates actions.
11
12
  class Engine
12
13
  include Singleton
13
14
  include Observable
14
15
 
15
- private
16
- def initialize
17
- end
18
-
19
- public
20
-
21
16
  # Evaluates whether or not the action is completed.
22
17
  def action_eval!(action)
23
18
  ActionRules.instance.action_eval! action
24
19
  end
25
20
 
26
21
  def do_action(action)
27
- raise MonkeyEngine::Exceptions::InvalidOperationException.new \
28
- "The action [#{action.class.name}] for Monkey [#{action.monkey.monkey_symbol}] is already completed" if action.action_completed?
22
+ if action.action_completed?
23
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
24
+ "The action [#{action.class.name}] for Monkey [#{action.monkey.monkey_symbol}] is already completed"
25
+ end
29
26
 
30
27
  do_action_type(action) if action.is_a? MonkeyActionType
31
28
 
@@ -42,12 +39,12 @@ module MonkeyEngine
42
39
 
43
40
  # Returns a new action.
44
41
  def new_action(monkey)
45
- raise MonkeyEngine::Exceptions::InvalidOperationException.new \
46
- "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling new_action" \
47
- unless monkey.action.nil? || monkey.action.action_completed?
42
+ unless monkey.action.nil? || monkey.action.action_completed?
43
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
44
+ "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling new_action"
45
+ end
48
46
 
49
- return ActionRules.instance.get_next_action monkey
47
+ ActionRules.instance.get_next_action monkey
50
48
  end
51
-
52
49
  end
53
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MonkeyEngine
2
- VERSION = "1.1.0"
4
+ VERSION = '2.0.1'
3
5
  end
data/lib/MonkeyEngine.rb CHANGED
@@ -1 +1,3 @@
1
- require_relative 'MonkeyEngine/monkey_engine'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'MonkeyEngine/monkey_engine'
@@ -1,14 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'Monkey'
2
4
 
3
5
  module MonkeyFactory
4
-
5
6
  class << self
6
-
7
- public
8
7
  def create(monkey_symbol)
9
8
  # Call the protected constructor - monkeys can only be created
10
9
  # via the MonkeyFactory.
11
10
  Monkey.send(:new, monkey_symbol)
12
11
  end
13
12
  end
14
- end
13
+ end
data/lib/MonkeyFactory.rb CHANGED
@@ -1 +1,3 @@
1
- require_relative 'MonkeyFactory/monkey_factory'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'MonkeyFactory/monkey_factory'
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Represents a keyboard character.
2
4
  class KeyboardChar
3
-
4
5
  attr_reader :char
5
6
 
6
7
  def initialize(char)
7
8
  @char = char
8
- self
9
9
  end
10
- end
10
+ end
@@ -1,14 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Represents keyboard input.
2
4
  class KeyboardInput
3
-
4
5
  attr_accessor :is_word, :input
5
6
 
6
7
  def initialize
7
8
  @is_word = false
8
- @input = Array.new
9
+ @input = []
9
10
  end
10
11
 
11
12
  def input_to_s
12
13
  @input.join.to_s
13
14
  end
14
- end
15
+ end