Class: Spek::Picker
- Inherits:
-
Object
- Object
- Spek::Picker
- Defined in:
- lib/spek/picker.rb
Overview
Picks a gem specification.
Class Method Summary collapse
Instance Method Summary collapse
- #call(name) ⇒ Object
- #choose(specifications) ⇒ Object
-
#initialize(finder: Finder.new, kernel: Kernel) ⇒ Picker
constructor
A new instance of Picker.
Constructor Details
#initialize(finder: Finder.new, kernel: Kernel) ⇒ Picker
Returns a new instance of Picker.
12 13 14 15 |
# File 'lib/spek/picker.rb', line 12 def initialize finder: Finder.new, kernel: Kernel @finder = finder @kernel = kernel end |
Class Method Details
.call(name) ⇒ Object
10 |
# File 'lib/spek/picker.rb', line 10 def self.call(name, ...) = new(...).call name |
Instance Method Details
#call(name) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/spek/picker.rb', line 17 def call name specifications = finder.call name case specifications.size when 1 then Success specifications.first when 2.. then Success choose(specifications) else Failure "Unknown or uninstalled gem: #{name}." end end |
#choose(specifications) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/spek/picker.rb', line 27 def choose specifications specifications.each.with_index 1 do |specification, index| kernel.puts "#{index}. #{specification.named_version}" end kernel.puts "\nPlease enter gem selection:" ARGV.clear specifications[kernel.gets.chomp.to_i - 1] end |