Class: HighLine::Menu::Item

Inherits:
Object show all
Defined in:
lib/highline/menu/item.rb

Overview

Represents an Item of a HighLine::Menu.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes) ⇒ Item

Returns a new instance of Item.

Parameters:

  • name (String)

    The name that is matched against the user input

  • attributes (Hash)

    options Hash to tailor menu item to your needs

Options Hash (attributes):

  • text: (String)

    The text that displays for that choice (defaults to name)

  • help: (String)

    help/hint string to be displayed.

  • action: (Block)

    a block that gets called when choice is selected



19
20
21
22
23
24
# File 'lib/highline/menu/item.rb', line 19

def initialize(name, attributes)
  @name = name
  @text = attributes[:text] || @name
  @help = attributes[:help]
  @action = attributes[:action]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/highline/menu/item.rb', line 8

def action
  @action
end

#helpObject (readonly)

Returns the value of attribute help.



8
9
10
# File 'lib/highline/menu/item.rb', line 8

def help
  @help
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/highline/menu/item.rb', line 8

def name
  @name
end

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/highline/menu/item.rb', line 8

def text
  @text
end

Instance Method Details

#item_helpObject



26
27
28
29
# File 'lib/highline/menu/item.rb', line 26

def item_help
  return {} unless help
  { name.to_s.downcase => help }
end