Module: SectionTrees
- Defined in:
- app/my_lib/section_trees.rb
Class Method Summary collapse
-
.build_group_section_trees(packages) ⇒ Object
build group_sections_attributes from packages parameters result format: [{ pricing_menu_id: 1, quantity: 2, pricing_menu_name: 'Menu Name', original_price_cents: 10000, selling_price_cents: 8000, section_type: 'food' }].
- .build_group_sections_from_reservation(reservation) ⇒ Object
-
.build_section_trees(packages) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
.build_section_trees_from_reservation(reservation) ⇒ Object
build menu_sections data from reservation result [ { id:1, menus: [1, quantity: 2]} ].
Class Method Details
.build_group_section_trees(packages) ⇒ Object
build group_sections_attributes from packages parameters result format: [{ pricing_menu_id: 1, quantity: 2, pricing_menu_name: 'Menu Name', original_price_cents: 10000, selling_price_cents: 8000, section_type: 'food' }]
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/my_lib/section_trees.rb', line 78 def self.build_group_section_trees(packages) group_sections = [] return group_sections if packages.blank? packages.each do |package| next if package[:group_sections].blank? package[:group_sections].each do |group_section| = group_section[:id] quantity = group_section[:quantity] next unless quantity.to_i.positive? # Fetch pricing menu data to populate the new columns = HhPackage::PricingMenu.find_by(id: ) section = { pricing_menu_id: , quantity: quantity, } if # Use cents directly from pricing menu section[:pricing_menu_name] = .name section[:original_price_cents] = .original_price_cents section[:original_price_currency] = .original_price_currency section[:selling_price_cents] = .selling_price_cents section[:selling_price_currency] = .selling_price_currency section[:section_type] = .section_type end group_sections.push section end end group_sections end |
.build_group_sections_from_reservation(reservation) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/my_lib/section_trees.rb', line 61 def self.build_group_sections_from_reservation(reservation) group_sections = [] return group_sections if reservation.group_sections.blank? reservation.group_sections.each do |group_section| section = { id: group_section., quantity: group_section.quantity, } group_sections.push section end group_sections end |
.build_section_trees(packages) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/my_lib/section_trees.rb', line 3 def self.build_section_trees(packages) # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity section_trees = if packages.select { |p| p[:sections].present? }.present? packages.pluck(:sections).flatten.map(&:to_h) else packages.pluck(:menu_sections).flatten.map(&:to_h) end # rubocop:disable Style/MultilineBlockChain section_trees.each do |s| s[:package_menu_section_id] = s.delete :id s.delete :name s.delete :quantity_limit next if s[:menus].blank? s[:menus_attributes] = s.delete(:menus).select do |m| m[:quantity].to_i.positive? end.each do || .delete :name [:package_menu_id] = .delete :id next if [:subsections].blank? [:subsections].delete_if { |section| section[:menus].blank? } [:subsections_attributes] = .delete(:subsections) [:subsections_attributes] = [:subsections_attributes].each do |ss| ss[:package_menu_section_id] = ss.delete :id ss.delete :name ss.delete :quantity_limit ss[:menus_attributes] = ss.delete(:menus).select do |sm| sm[:quantity].to_i.positive? end.each do || .delete :name [:package_menu_id] = .delete :id end end end end.delete_if { |section| section[:menus_attributes].blank? } # rubocop:enable Style/MultilineBlockChain end |
.build_section_trees_from_reservation(reservation) ⇒ Object
build menu_sections data from reservation result
- { id:1, menus: [1, quantity: 2]}
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/my_lib/section_trees.rb', line 45 def self.build_section_trees_from_reservation(reservation) = [] return if reservation..blank? reservation..each do || section = { id: ., menus: ..map { |m| { id: m., quantity: m.quantity } }, } .push section end end |