Class: SshMenu::Selector
- Inherits:
-
Object
- Object
- SshMenu::Selector
- Defined in:
- lib/sshmenu/selector.rb
Instance Method Summary collapse
- #connection_list ⇒ Object
-
#initialize(connections) ⇒ Selector
constructor
A new instance of Selector.
- #request_selection ⇒ Object
- #select ⇒ Object
Constructor Details
#initialize(connections) ⇒ Selector
Returns a new instance of Selector.
4 5 6 |
# File 'lib/sshmenu/selector.rb', line 4 def initialize(connections) @connections = connections end |
Instance Method Details
#connection_list ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sshmenu/selector.rb', line 29 def connection_list uh_length = @connections.map {|conn| conn['user_host'].length}.max index_length = @connections.size.to_s.length s = StringIO.new @connections.each.with_index do |connection, index| conn = connection['user_host'] desc = connection['description'] s << "%#{index_length}d) %-#{uh_length+3}s %s\n" % [ index+1, conn, desc] end s.string end |
#request_selection ⇒ Object
23 24 25 26 27 |
# File 'lib/sshmenu/selector.rb', line 23 def request_selection puts connection_list print 'Pick a server (or e to edit connections): ' STDIN.gets.chomp end |
#select ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sshmenu/selector.rb', line 8 def select selection = request_selection case selection when /\A[eE]\z/ {:action => :edit} when /\A[1-9][0-9]*\z/ {:index => Integer(selection) - 1 } when /\A\z/ {} else raise ArgumentError, "invalid selection '#{selection}'" end end |