Class: Anoubis::Output::Menu
- Defined in:
- app/controllers/anoubis/output/menu.rb
Overview
Output subclass that represents data for menu action
Instance Attribute Summary collapse
-
#items ⇒ Array
The array of menu elements MenuItem.
-
#keys ⇒ Hash
The hash of menu elements MenuItem with ‘mode’ as a key.
-
#user ⇒ Hash
The hash of user information.
Attributes inherited from Basic
#messages, #result, #tab, #title
Instance Method Summary collapse
-
#addElement(options) ⇒ Object
Adds new element into menu hash.
-
#initialize ⇒ Menu
constructor
Initializes menu output data.
-
#key(mode) ⇒ MenuItem | nil
Returns menu element.
-
#message ⇒ String
Generates output message based on self.result variable.
-
#to_h ⇒ Hash
Generates hash representation of output class.
Methods inherited from Basic
#hash_to_json, #options_to_json
Constructor Details
#initialize ⇒ Menu
Initializes menu output data. Generates default values.
20 21 22 23 24 25 |
# File 'app/controllers/anoubis/output/menu.rb', line 20 def initialize super self.items = [] self.keys = {} self.user = {} end |
Instance Attribute Details
#items ⇒ Array
Returns the array of menu elements Anoubis::Output::MenuItem.
8 |
# File 'app/controllers/anoubis/output/menu.rb', line 8 class_attribute :items |
#keys ⇒ Hash
Returns the hash of menu elements Anoubis::Output::MenuItem with ‘mode’ as a key.
12 |
# File 'app/controllers/anoubis/output/menu.rb', line 12 class_attribute :keys |
#user ⇒ Hash
Returns the hash of user information.
16 |
# File 'app/controllers/anoubis/output/menu.rb', line 16 class_attribute :user |
Instance Method Details
#addElement(options) ⇒ Object
Adds new element into menu hash
39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/anoubis/output/menu.rb', line 39 def addElement() if .has_key? :parent if !self.keys.has_key? [:parent].to_s.to_sym [:parent] = nil end end = MenuItem.new self.items.push self.keys[.mode.to_s.to_sym] = self.items[self.items.count-1] end |
#key(mode) ⇒ MenuItem | nil
Returns menu element
80 81 82 83 84 85 86 87 |
# File 'app/controllers/anoubis/output/menu.rb', line 80 def key(mode) if self.keys.has_key? mode.to_s.to_sym return self.keys[mode.to_s.to_sym] else return nil end end |
#message ⇒ String
Generates output message based on self.result variable.
67 68 69 70 71 72 73 74 |
# File 'app/controllers/anoubis/output/menu.rb', line 67 def case self.result when 0 return I18n.t('success') else return I18n.t('invalid_menu_output') end end |
#to_h ⇒ Hash
Generates hash representation of output class
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/anoubis/output/menu.rb', line 53 def to_h result = super.to_h return result if self.result != 0 result[:menu] = [] self.items.each { |item| result[:menu].push(item.to_h) if item } result[:user] = self.user result end |