Class: CommandButler::Input
- Inherits:
-
Object
- Object
- CommandButler::Input
- Defined in:
- lib/command_butler/input.rb
Defined Under Namespace
Modules: VALUE
Instance Attribute Summary collapse
-
#input_value ⇒ Object
readonly
Returns the value of attribute input_value.
Class Method Summary collapse
- .constant_inputs?(input_value) ⇒ Boolean
- .execute_instance ⇒ Object
- .skip_instance ⇒ Object
- .start ⇒ Object
Instance Method Summary collapse
- #abort? ⇒ Boolean
- #execute? ⇒ Boolean
-
#initialize(input_value: input_value) ⇒ Input
constructor
A new instance of Input.
- #jump? ⇒ Boolean
- #skip? ⇒ Boolean
Constructor Details
#initialize(input_value: input_value) ⇒ Input
Returns a new instance of Input.
11 12 13 |
# File 'lib/command_butler/input.rb', line 11 def initialize(input_value:input_value) @input_value = input_value end |
Instance Attribute Details
#input_value ⇒ Object (readonly)
Returns the value of attribute input_value.
4 5 6 |
# File 'lib/command_butler/input.rb', line 4 def input_value @input_value end |
Class Method Details
.constant_inputs?(input_value) ⇒ Boolean
15 16 17 |
# File 'lib/command_butler/input.rb', line 15 def self.constant_inputs?(input_value) VALUE.constants.map{|c| VALUE.const_get(c)}.flatten.include? input_value end |
.execute_instance ⇒ Object
23 24 25 |
# File 'lib/command_butler/input.rb', line 23 def self.execute_instance self.new(input_value:VALUE::EXECUTE) end |
.skip_instance ⇒ Object
19 20 21 |
# File 'lib/command_butler/input.rb', line 19 def self.skip_instance self.new(input_value:VALUE::SKIP) end |
.start ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/command_butler/input.rb', line 27 def self.start while(true) puts "[#{Dir.pwd}] $ execute Enter (no: n, quit: q, jump : command-number, skip : s)\n" input_value = STDIN.gets.chomp input_value = 'y' if input_value == "" # エンターの実行はyと同じにする return self.new(input_value:input_value) if constant_inputs? input_value return self.new(input_value:input_value.to_i) if input_value.to_i.nonzero? # jumpコマンド end end |
Instance Method Details
#abort? ⇒ Boolean
49 50 51 |
# File 'lib/command_butler/input.rb', line 49 def abort? (VALUE::ABORT).include? @input_value end |
#execute? ⇒ Boolean
41 42 43 |
# File 'lib/command_butler/input.rb', line 41 def execute? (VALUE::EXECUTE).include? @input_value end |
#jump? ⇒ Boolean
37 38 39 |
# File 'lib/command_butler/input.rb', line 37 def jump? @input_value.is_a? Integer end |