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.

Methods

host?   menu?   new   new_from_array   new_from_hash   separator?   title   to_h  

Attributes

type  [R]  e.g.: ‘separator’, ‘host’ or ‘menu‘

Public Class methods

Default constructor.

[Source]

# File lib/sshmenu.rb, line 1542
    def initialize(type)
      @type = type
    end

Called from SSHMenu::Config#set_items_from_array to construct item objects from the array of hashes in the config file.

[Source]

# 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.

[Source]

# 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

Public Instance methods

Returns true if the item is of type ‘host’.

[Source]

# File lib/sshmenu.rb, line 1580
    def host?
      return @type == 'host'
    end

Returns true if the item is of type ‘menu’.

[Source]

# File lib/sshmenu.rb, line 1586
    def menu?
      return @type == 'menu'
    end

Returns true if the item is of type ‘separator’.

[Source]

# File lib/sshmenu.rb, line 1592
    def separator?
      return @type == 'separator'
    end

Provides a default title (overridden by host and menu items).

[Source]

# File lib/sshmenu.rb, line 1574
    def title
      return "Item #{object_id}"
    end

Serialises the item to a hash (overridden by derived classes).

[Source]

# File lib/sshmenu.rb, line 1598
    def to_h
      return { 'type' => @type }
    end

[Validate]