Class: Rlocu::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/rlocu/menu.rb

Defined Under Namespace

Classes: Item, MenuItem, Option, OptionGroup, Section, SectionText, Subsection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(menu_hash) ⇒ Menu

Returns a new instance of Menu.



5
6
7
8
# File 'lib/rlocu/menu.rb', line 5

def initialize(menu_hash)
  @menu_name = menu_hash['menu_name']
  self.sections = menu_hash['sections']
end

Instance Attribute Details

Returns the value of attribute menu_name.



3
4
5
# File 'lib/rlocu/menu.rb', line 3

def menu_name
  @menu_name
end

#sectionsObject

Returns the value of attribute sections.



3
4
5
# File 'lib/rlocu/menu.rb', line 3

def sections
  @sections
end

Instance Method Details

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rlocu/menu.rb', line 15

def to_s
  str = "Menu: #{menu_name}\n"
  sections.each do |section|
    str << "-----#{section.section_name}-----\n"
    section.subsections.each do |subsection|
      str << "---#{subsection.subsection_name}---\n"
      subsection.contents.each do |content|
        case content
        when SectionText
          str << "SECTION TEXT : #{content.to_s}\n"
        when MenuItem
          str << "MENU ITEM : #{content.name} #{content.description} #{content.price}\n"
          content.option_groups.each do |opt_group|
            str << "OPTION GROUP : #{opt_group.text}\n"
            opt_group.options.each do |option|
              str << "OPTION  :  #{option.to_s}\n"
            end
          end
        end
      end
    end
  end
  str
end