Class: RubiksCli::Loop::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/rubiks_cli/loop/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(on_enter, other_actions) ⇒ Engine

Returns a new instance of Engine.



8
9
10
11
12
13
14
15
16
# File 'lib/rubiks_cli/loop/engine.rb', line 8

def initialize(on_enter, other_actions)
  commands = other_actions.map { |action| action.command }
  if commands.uniq.size != commands.size
    raise ArgumentError, "Duplicate command"
  end

  @actions = Hash.new(on_enter)
  other_actions.each { |action| @actions[action.command] = action.function }
end

Instance Method Details

#startObject



18
19
20
21
22
23
24
25
# File 'lib/rubiks_cli/loop/engine.rb', line 18

def start
  @actions['h'].call
  loop do
    input = gets.chomp.downcase
    Clear.line_above
    @actions[input].call
  end
end