Class: Input

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

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Input

Returns a new instance of Input.



9
10
11
# File 'lib/another_toy_robot/input.rb', line 9

def initialize(input)
  @input = input.strip.downcase
end

Instance Method Details

#basenameObject



13
14
15
# File 'lib/another_toy_robot/input.rb', line 13

def basename
  @basename ||= @input.split(" ").first
end

#paramsObject



17
18
19
# File 'lib/another_toy_robot/input.rb', line 17

def params
  @params ||= @input.split(" ").drop 1
end

#to_classObject



21
22
23
24
25
# File 'lib/another_toy_robot/input.rb', line 21

def to_class
  klass = "#{basename.capitalize}Command"
  return InvalidCommand unless Object.const_defined? klass
  Object.const_get klass
end