Class: Menu::SubselectMenu
- Includes:
- Listenable
- Defined in:
- lib/menu/subselect_menu.rb
Overview
menu class that inherits Base to abstract a menu which is used to query a subselect on an index
Instance Attribute Summary collapse
-
#criteria ⇒ Symbol
readonly
private
Criteria the ranking criteria.
-
#ranking ⇒ Array
readonly
private
An array that holds arrays of size two with [value, rank].
Attributes inherited from Base
#menu_description, #menu_items
Instance Method Summary collapse
-
#change_index(criteria) ⇒ Object
method to replace the current criteria.
-
#define_menu_items ⇒ Object
private
implementation to define the items of the menu.
-
#determine_action(input) ⇒ Object
private
method to specify the actions to a given input.
-
#initialize(ranking) ⇒ SubselectMenu
constructor
initialization as (attribute => occurrence).
Methods included from Listenable
#add_listener, #listeners, #notify_listeners, #remove_listener
Methods inherited from Base
#add_menu_item, #get_entry, #handle_wrong_option, #print_menu
Constructor Details
#initialize(ranking) ⇒ SubselectMenu
initialization as (attribute => occurrence)
16 17 18 19 20 |
# File 'lib/menu/subselect_menu.rb', line 16 def initialize(ranking) @menu_description = "Overview of the top n index results:" @ranking = ranking super end |
Instance Attribute Details
#criteria ⇒ Symbol (readonly, private)
Returns criteria the ranking criteria.
33 34 35 |
# File 'lib/menu/subselect_menu.rb', line 33 def criteria @criteria end |
#ranking ⇒ Array (readonly, private)
Returns an array that holds arrays of size two with [value, rank].
31 32 33 |
# File 'lib/menu/subselect_menu.rb', line 31 def ranking @ranking end |
Instance Method Details
#change_index(criteria) ⇒ Object
method to replace the current criteria
24 25 26 |
# File 'lib/menu/subselect_menu.rb', line 24 def change_index(criteria) @criteria = criteria end |
#define_menu_items ⇒ Object (private)
implementation to define the items of the menu
36 37 38 39 40 41 42 |
# File 'lib/menu/subselect_menu.rb', line 36 def @ranking.each { |entry| text = "#{entry[0]} [#{entry[1]}]" (text) } ("Return to previous menu.") end |
#determine_action(input) ⇒ Object (private)
method to specify the actions to a given input
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/menu/subselect_menu.rb', line 46 def determine_action(input) input_number = input.to_i case when (input_number == @menu_items.size) then return false when (input.to_i > @menu_items.size) || (input.to_i < 1) puts "Invalid input. Please try again." return false else = Menu::IndexSelectionMenu.new() .add_listener(:subselect_menu, self) . notify_listeners(:generate_subselect, @ranking[input.to_i - 1][0], @criteria) end end |