Class | SSHMenu::Item |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
SSHMenu::Item acts as a base for the SSHMenu::HostItem and SSHMenu::MenuItem classes and also is used to represent menu separator items.
type | [R] | e.g.: ‘separator’, ‘host’ or ‘menu‘ |
Called from SSHMenu::Config#set_items_from_array to construct item objects from the array of hashes in the config file.
# File lib/sshmenu.rb, line 1549 def Item.new_from_array(a) items = [] a.each { |h| items.push self.new_from_hash(h) } return items end
Alternate constructor. Based on the value of ‘type’ in the supplied hash, delegates construction to SSHMenu::HostItem or SSHMenu::MenuItem.
# File lib/sshmenu.rb, line 1558 def Item.new_from_hash(h) type = h['type'] || '' mapper = ClassMapper.instance if type == 'separator' return mapper.get_class('app.model.item').new('separator') elsif type == 'host' return mapper.get_class('app.model.hostitem').new(h) elsif type == 'menu' return mapper.get_class('app.model.menuitem').new(h) else puts "Ignoring item of unknown type '#{type}'" end end
Returns true if the item is of type ‘host’.
# File lib/sshmenu.rb, line 1580 def host? return @type == 'host' end
Returns true if the item is of type ‘menu’.
# File lib/sshmenu.rb, line 1586 def menu? return @type == 'menu' end
Returns true if the item is of type ‘separator’.
# File lib/sshmenu.rb, line 1592 def separator? return @type == 'separator' end