MonkeyEngine 1.0.0 → 2.0.0

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.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +19 -16
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +6 -0
  6. data/Gemfile +3 -1
  7. data/Gemfile.lock +71 -0
  8. data/README.md +5 -1
  9. data/Rakefile +3 -2
  10. data/dictionaries/en-US.txt +466554 -0
  11. data/lib/Action/action.rb +5 -4
  12. data/lib/Monkey/monkey.rb +17 -12
  13. data/lib/Monkey.rb +3 -1
  14. data/lib/MonkeyAction/monkey_action.rb +3 -1
  15. data/lib/MonkeyAction/monkey_action_dead.rb +8 -6
  16. data/lib/MonkeyAction/monkey_action_eat.rb +6 -4
  17. data/lib/MonkeyAction/monkey_action_pause.rb +6 -5
  18. data/lib/MonkeyAction/monkey_action_sleep.rb +6 -4
  19. data/lib/MonkeyAction/monkey_action_type.rb +15 -10
  20. data/lib/MonkeyAction/monkey_action_wake.rb +8 -6
  21. data/lib/MonkeyAction/monkey_timed_action.rb +6 -4
  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 +13 -10
  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 -2
  31. data/lib/MonkeyKeyboard/keyboard_input.rb +4 -3
  32. data/lib/MonkeyKeyboard/keyboard_key.rb +3 -1
  33. data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +5 -7
  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 +13 -11
  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 +64 -47
  41. data/monkeyengine.gemspec +22 -20
  42. data/spec/action_rules_spec.rb +9 -9
  43. data/spec/engine_spec.rb +5 -10
  44. data/spec/keyboard_char_spec.rb +3 -4
  45. data/spec/keyboard_key_spec.rb +3 -4
  46. data/spec/monkey_action_eat_spec.rb +14 -15
  47. data/spec/monkey_action_pause_spec.rb +15 -16
  48. data/spec/monkey_action_sleep_spec.rb +15 -16
  49. data/spec/monkey_action_type_spec.rb +22 -21
  50. data/spec/monkey_action_wake_spec.rb +6 -7
  51. data/spec/monkey_factory_spec.rb +5 -5
  52. data/spec/monkey_keyboard_en_us_spec.rb +8 -14
  53. data/spec/monkey_manager_spec.rb +2 -1
  54. data/spec/monkey_service_spec.rb +15 -18
  55. data/spec/monkey_spec.rb +2 -1
  56. data/spec/{spec_helpers.rb → spec_helper.rb} +6 -4
  57. data/spec/support/shared_examples.rb +12 -12
  58. metadata +72 -56
  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.
@@ -18,12 +20,11 @@ class Action
18
20
  @action_completed
19
21
  end
20
22
 
21
- def action_completed=(value)
22
- @action_completed = value
23
- end
23
+ attr_writer :action_completed
24
24
 
25
25
  protected
26
+
26
27
  def validate
27
28
  # throw if invalid state
28
29
  end
29
- end
30
+ 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,6 +27,7 @@ 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
@@ -43,6 +44,7 @@ class Monkey
43
44
  #
44
45
  def alive?
45
46
  return false if @thread.nil?
47
+
46
48
  @thread.alive?
47
49
  end
48
50
 
@@ -52,6 +54,7 @@ class Monkey
52
54
  #
53
55
  def current_action
54
56
  return MonkeyActionDead.new(self) unless alive?
57
+
55
58
  @action
56
59
  end
57
60
 
@@ -71,8 +74,11 @@ class Monkey
71
74
  # @return [Monkey, self]
72
75
  #
73
76
  def start
74
- raise MonkeyEngine::Exceptions::InvalidOperationException.new "The monkey [#{@monkey_symbol}] thread is already started" \
75
- if alive?
77
+ if alive?
78
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
79
+ "The monkey [#{@monkey_symbol}] thread is already started"
80
+ end
81
+
76
82
  initialize_thread
77
83
  self
78
84
  end
@@ -81,28 +87,27 @@ class Monkey
81
87
  #
82
88
  # @return [Thread]
83
89
  #
84
- def thread
85
- @thread
86
- end
90
+ attr_reader :thread
87
91
 
88
92
  protected
93
+
89
94
  def initialize_thread
90
- @sleep_time = 1.0/250.0
95
+ @sleep_time = 1.0 / 250.0
91
96
  @kill_thread = false
92
97
 
93
- @thread = Thread.new {
98
+ @thread = Thread.new do
94
99
  monkey_do
95
- }
100
+ end
96
101
 
97
- #@thread.freeze
102
+ # @thread.freeze
98
103
  @thread.abort_on_exception = true
99
104
  end
100
105
 
101
106
  def monkey_do
102
- until @kill_thread do
107
+ until @kill_thread
103
108
  @action = @monkey_service.new_action(self) if @action.nil? || @action.action_completed?
104
109
  @monkey_service.monkey_do @action unless @monkey_service.action_eval! @action
105
110
  sleep(@sleep_time)
106
111
  end
107
112
  end
108
- end
113
+ 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.
@@ -11,4 +13,4 @@ class MonkeyAction < Action
11
13
 
12
14
  self
13
15
  end
14
- end
16
+ end
@@ -1,15 +1,16 @@
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
 
@@ -17,10 +18,11 @@ class MonkeyActionDead < MonkeyAction
17
18
  end
18
19
 
19
20
  protected
21
+
20
22
  def validate
21
23
  super
22
24
 
23
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
24
- if !VALID_VALUES.include?(@value)
25
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
26
+ unless VALID_VALUES.include?(@value)
25
27
  end
26
- end
28
+ 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
 
@@ -22,10 +23,11 @@ class MonkeyActionEat < MonkeyTimedAction
22
23
  end
23
24
 
24
25
  protected
26
+
25
27
  def validate
26
28
  super
27
29
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
30
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
31
+ unless VALID_VALUES.include?(@value)
30
32
  end
31
- end
33
+ 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
 
@@ -22,11 +23,11 @@ class MonkeyActionPause < MonkeyTimedAction
22
23
  end
23
24
 
24
25
  protected
26
+
25
27
  def validate
26
28
  super
27
29
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
30
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
31
+ unless VALID_VALUES.include?(@value)
30
32
  end
31
-
32
- end
33
+ 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
 
@@ -22,10 +23,11 @@ class MonkeyActionSleep < MonkeyTimedAction
22
23
  end
23
24
 
24
25
  protected
26
+
25
27
  def validate
26
28
  super
27
29
 
28
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
29
- if !VALID_VALUES.include?(@value)
30
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
31
+ unless VALID_VALUES.include?(@value)
30
32
  end
31
- end
33
+ end
@@ -1,20 +1,23 @@
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
 
@@ -26,15 +29,17 @@ class MonkeyActionType < MonkeyAction
26
29
  end
27
30
 
28
31
  protected
29
- def validate
30
32
 
31
- raise MonkeyEngine::Exceptions::NilArgumentException.new "Value '#{value}' cannot be nil" \
33
+ def validate
34
+ raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
32
35
  if @value.nil?
33
36
 
34
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "Value '#{value}' is not a valid argument type (#{value.class.name})" \
35
- unless @value.is_a?(Array)
37
+ unless @value.is_a?(Array)
38
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
39
+ "Value '#{value}' is not a valid argument type (#{value.class.name})"
40
+ end
36
41
 
37
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' cannot be empty" \
42
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' cannot be empty" \
38
43
  if @value.empty?
39
44
  end
40
- end
45
+ end
@@ -1,15 +1,16 @@
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
 
@@ -17,10 +18,11 @@ class MonkeyActionWake < MonkeyAction
17
18
  end
18
19
 
19
20
  protected
21
+
20
22
  def validate
21
23
  super
22
24
 
23
- raise MonkeyEngine::Exceptions::InvalidArgumentValueException.new "Value '#{value}' is not a valid value" \
24
- if !VALID_VALUES.include?(@value)
25
+ raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
26
+ unless VALID_VALUES.include?(@value)
25
27
  end
26
- end
28
+ 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)
@@ -17,11 +18,12 @@ class MonkeyTimedAction < MonkeyAction
17
18
  end
18
19
 
19
20
  protected
21
+
20
22
  def validate
21
- raise MonkeyEngine::Exceptions::NilArgumentException.new "Value '#{value}' cannot be nil" \
23
+ raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
22
24
  if @value.nil?
23
25
 
24
- raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "Value '#{value}' is not a valid argument type" \
26
+ raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, "Value '#{value}' is not a valid argument type" \
25
27
  unless @value.is_a?(Integer)
26
28
  end
27
- end
29
+ 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,15 +8,14 @@ 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
16
  private
16
- def initialize
17
- end
17
+
18
+ def initialize; end
18
19
 
19
20
  public
20
21
 
@@ -24,8 +25,10 @@ module MonkeyEngine
24
25
  end
25
26
 
26
27
  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?
28
+ if action.action_completed?
29
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
30
+ "The action [#{action.class.name}] for Monkey [#{action.monkey.monkey_symbol}] is already completed"
31
+ end
29
32
 
30
33
  do_action_type(action) if action.is_a? MonkeyActionType
31
34
 
@@ -42,12 +45,12 @@ module MonkeyEngine
42
45
 
43
46
  # Returns a new action.
44
47
  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?
48
+ unless monkey.action.nil? || monkey.action.action_completed?
49
+ raise MonkeyEngine::Exceptions::InvalidOperationException,
50
+ "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling new_action"
51
+ end
48
52
 
49
- return ActionRules.instance.get_next_action monkey
53
+ ActionRules.instance.get_next_action monkey
50
54
  end
51
-
52
55
  end
53
56
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MonkeyEngine
2
- VERSION = "1.0.0"
4
+ VERSION = '2.0.0'
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,11 @@
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
9
  self
9
10
  end
10
- end
11
+ 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'keyboard_char'
2
4
 
3
5
  # Represents a keyboard key.
@@ -23,4 +25,4 @@ class KeyboardKey
23
25
 
24
26
  KeyboardKey.new keyboard_char, keyboard_shift_char, keyboard_key_section, keyboard_key_weight
25
27
  end
26
- end
28
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class KeyboardKeyEvaluator
2
4
  def initialize
3
5
  @shift_on = false
@@ -10,16 +12,12 @@ class KeyboardKeyEvaluator
10
12
 
11
13
  return nil if keyboard_key.keyboard_char.char.is_a? Symbol
12
14
 
13
- if @shift_on
14
- return keyboard_key.keyboard_shift_char.char
15
- end
15
+ return keyboard_key.keyboard_shift_char.char if @shift_on
16
16
 
17
17
  char = keyboard_key.keyboard_char.char
18
18
 
19
- if @caps_on
20
- return char.upcase
21
- end
19
+ return char.upcase if @caps_on
22
20
 
23
21
  char
24
22
  end
25
- end
23
+ end