Class SSHMenu::MenuItem
In: lib/sshmenu.rb  (Git)
Parent: Item

The SSHMenu::MenuItem is used as a container for the configuration options associated with a sub-menu. The object‘s only properties are the title and the array of child items. Inherits from SSHMenu::Item.

Methods

Attributes

items  [R]  An array of SSHMenu::Item children.
title  [RW]  The menu title.

Public Class methods

Constructor. Attributes hash should contain ‘title’ and ‘items’ keys. Any other keys will be discarded.

[Source]

# File lib/sshmenu.rb, line 1700
    def initialize(h={})
      @type  = 'menu'
      @title = h['title'] || ''
      @items = []
      mapper = ClassMapper.instance
      item_class = mapper.get_class('app.model.item')
      (h['items'] || []).each { |h| @items.push item_class.new_from_hash(h) }
    end

Public Instance methods

Adds a new item onto the end of the list of children.

[Source]

# File lib/sshmenu.rb, line 1723
    def append_item(item)
      @items.push item
    end

Discards all child items.

[Source]

# File lib/sshmenu.rb, line 1717
    def clear_items
      @items = []
    end

Returns true if the menu contains any items (i.e.: is not empty).

[Source]

# File lib/sshmenu.rb, line 1711
    def has_children?
      @items.length > 0
    end

Serialises the menu title and child items to a hash.

[Source]

# File lib/sshmenu.rb, line 1729
    def to_h
      return {
        'type'  => 'menu',
        'title' => @title,
        'items' => @items.map { |i| i.to_h }
      }
    end

[Validate]