Class: PPCurses::MenuItem
- Inherits:
-
Object
- Object
- PPCurses::MenuItem
- Defined in:
- lib/ppcurses/menu/menu_item.rb
Instance Attribute Summary collapse
-
#selectable ⇒ Object
Returns the value of attribute selectable.
-
#state ⇒ Object
Returns the value of attribute state.
-
#target ⇒ Object
Who to notify when menu is selected chosen? The target should be a method selector, and.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #call_target ⇒ Object
- #display_string ⇒ Object
- #handle_key(key) ⇒ Object
-
#initialize(title) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #toggle_on_off_state ⇒ Object
Constructor Details
#initialize(title) ⇒ MenuItem
Returns a new instance of MenuItem.
21 22 23 24 25 |
# File 'lib/ppcurses/menu/menu_item.rb', line 21 def initialize( title ) @title = title @state = PP_OFF_STATE @selectable = false end |
Instance Attribute Details
#selectable ⇒ Object
Returns the value of attribute selectable.
19 20 21 |
# File 'lib/ppcurses/menu/menu_item.rb', line 19 def selectable @selectable end |
#state ⇒ Object
Returns the value of attribute state.
18 19 20 |
# File 'lib/ppcurses/menu/menu_item.rb', line 18 def state @state end |
#target ⇒ Object
Who to notify when menu is selected chosen? The target should be a method selector, and
16 17 18 |
# File 'lib/ppcurses/menu/menu_item.rb', line 16 def target @target end |
#title ⇒ Object
Returns the value of attribute title.
12 13 14 |
# File 'lib/ppcurses/menu/menu_item.rb', line 12 def title @title end |
Instance Method Details
#call_target ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ppcurses/menu/menu_item.rb', line 48 def call_target unless @target.nil? case @target.arity when 0 @target.call when 1 @target.call(self) else raise ArgumentError, "Too many parameters for target don't know what to do" end end end |
#display_string ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ppcurses/menu/menu_item.rb', line 27 def display_string if @state == PP_OFF_STATE return ' ' + @title end SELECTED_CHAR + ' ' + @title end |
#handle_key(key) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ppcurses/menu/menu_item.rb', line 63 def handle_key(key) if key == ' ' and @selectable toggle_on_off_state call_target return true end if key == ENTER call_target return true end false end |
#toggle_on_off_state ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ppcurses/menu/menu_item.rb', line 36 def toggle_on_off_state if @state == PP_OFF_STATE @state = PP_ON_STATE return end if @state == PP_ON_STATE @state = PP_OFF_STATE end end |