Sha256: 50d81e17d846458c150cc1650e59cedebe067987cd559ab30ae5210962430fdc
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
module CommandButler class Input attr_reader :input_value module VALUE EXECUTE = %w(y yes) SKIP = %w(s skip n no) ABORT = %w(a abort q quit) end def initialize(input_value:input_value) @input_value = input_value end def self.constant_inputs?(input_value) VALUE.constants.map{|c| VALUE.const_get(c)}.flatten.include? input_value end def self.skip_instance self.new(input_value:VALUE::SKIP) end def self.execute_instance self.new(input_value:VALUE::EXECUTE) end 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 def jump? @input_value.is_a? Integer end def execute? (VALUE::EXECUTE).include? @input_value end def skip? (VALUE::SKIP).include? @input_value end def abort? (VALUE::ABORT).include? @input_value end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
command_butler-0.0.3 | lib/command_butler/input.rb |
command_butler-0.0.2 | lib/command_butler/input.rb |
command_butler-0.0.1 | lib/command_butler/input.rb |