Class: Soyuz::CommandChoice
- Inherits:
-
Object
- Object
- Soyuz::CommandChoice
- Defined in:
- lib/soyuz/command_choice.rb
Instance Method Summary collapse
- #build_command(choice) ⇒ Object
-
#initialize(choices) ⇒ CommandChoice
constructor
A new instance of CommandChoice.
- #run ⇒ Object
Constructor Details
#initialize(choices) ⇒ CommandChoice
Returns a new instance of CommandChoice.
6 7 8 9 |
# File 'lib/soyuz/command_choice.rb', line 6 def initialize(choices) raise ArgumentError, "Choices must be an array" unless choices.is_a?(Array) @choices = choices end |
Instance Method Details
#build_command(choice) ⇒ Object
19 20 21 |
# File 'lib/soyuz/command_choice.rb', line 19 def build_command(choice) Command.build(@choices[choice][:cmd]).run end |
#run ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/soyuz/command_choice.rb', line 11 def run @choices.each_with_index do |choice, index| say "#{index+1}) #{choice[:display]}" end choice = ask("? ", Integer) { |q| q.in = 1..@choices.length } build_command(choice-1) end |