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.



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.


# 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) }

Public Instance methods

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


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

Discards all child items.


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

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


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

Serialises the menu title and child items to a hash.


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