Class: CommandButler::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/command_butler/input.rb

Defined Under Namespace

Modules: VALUE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_valueObject (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

Returns:

  • (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_instanceObject



23
24
25
# File 'lib/command_butler/input.rb', line 23

def self.execute_instance
  self.new(input_value:VALUE::EXECUTE)
end

.skip_instanceObject



19
20
21
# File 'lib/command_butler/input.rb', line 19

def self.skip_instance
  self.new(input_value:VALUE::SKIP)
end

.startObject



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

Returns:

  • (Boolean)


49
50
51
# File 'lib/command_butler/input.rb', line 49

def abort?
  (VALUE::ABORT).include? @input_value
end

#execute?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/command_butler/input.rb', line 41

def execute?
  (VALUE::EXECUTE).include? @input_value
end

#jump?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/command_butler/input.rb', line 37

def jump?
  @input_value.is_a? Integer
end

#skip?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/command_butler/input.rb', line 45

def skip?
  (VALUE::SKIP).include? @input_value
end