Class: CloverSandboxSimulator::Generators::DataLoader
- Inherits:
-
Object
- Object
- CloverSandboxSimulator::Generators::DataLoader
- Defined in:
- lib/clover_sandbox_simulator/generators/data_loader.rb
Overview
Loads data from JSON files for different business types
Instance Attribute Summary collapse
-
#business_type ⇒ Object
readonly
Returns the value of attribute business_type.
Instance Method Summary collapse
-
#active_combos ⇒ Object
Get active combos.
-
#active_coupon_codes ⇒ Object
Get active coupon codes.
- #categories ⇒ Object
-
#category_tax_mapping ⇒ Object
Load category to tax rate mapping.
-
#combos ⇒ Object
Load combo definitions.
-
#coupon_codes ⇒ Object
Load coupon codes.
- #discounts ⇒ Object
-
#discounts_by_type(type) ⇒ Object
Get discounts by type.
-
#find_combo(combo_id) ⇒ Object
Find combo by ID.
-
#find_coupon(code) ⇒ Object
Find coupon by code.
-
#initialize(business_type: :restaurant) ⇒ DataLoader
constructor
A new instance of DataLoader.
- #items ⇒ Object
- #items_for_category(category_name) ⇒ Object
-
#line_item_discounts ⇒ Object
Get line-item discounts.
-
#loyalty_discounts ⇒ Object
Get loyalty discounts.
- #modifiers ⇒ Object
-
#tax_rates ⇒ Object
Load tax rate definitions.
- #tenders ⇒ Object
-
#threshold_discounts ⇒ Object
Get threshold discounts.
-
#time_based_discounts ⇒ Object
Get time-based discounts.
Constructor Details
#initialize(business_type: :restaurant) ⇒ DataLoader
Returns a new instance of DataLoader.
9 10 11 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 9 def initialize(business_type: :restaurant) @business_type = business_type end |
Instance Attribute Details
#business_type ⇒ Object (readonly)
Returns the value of attribute business_type.
7 8 9 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 7 def business_type @business_type end |
Instance Method Details
#active_combos ⇒ Object
Get active combos
96 97 98 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 96 def active_combos combos.select { |c| c["active"] } end |
#active_coupon_codes ⇒ Object
Get active coupon codes
91 92 93 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 91 def active_coupon_codes coupon_codes.select { |c| c["active"] } end |
#categories ⇒ Object
13 14 15 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 13 def categories @categories ||= load_json("categories")["categories"] end |
#category_tax_mapping ⇒ Object
Load category to tax rate mapping
55 56 57 58 59 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 55 def category_tax_mapping @category_tax_mapping ||= load_json("tax_rates")["category_tax_mapping"] rescue Error {} # Return empty hash if file doesn't exist end |
#combos ⇒ Object
Load combo definitions
41 42 43 44 45 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 41 def combos @combos ||= load_json("combos")["combos"] rescue Error [] # Return empty array if file doesn't exist end |
#coupon_codes ⇒ Object
Load coupon codes
34 35 36 37 38 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 34 def coupon_codes @coupon_codes ||= load_json("coupon_codes")["coupon_codes"] rescue Error [] # Return empty array if file doesn't exist end |
#discounts ⇒ Object
21 22 23 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 21 def discounts @discounts ||= load_json("discounts")["discounts"] end |
#discounts_by_type(type) ⇒ Object
Get discounts by type
66 67 68 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 66 def discounts_by_type(type) discounts.select { |d| d["type"] == type } end |
#find_combo(combo_id) ⇒ Object
Find combo by ID
106 107 108 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 106 def find_combo(combo_id) combos.find { |c| c["id"] == combo_id } end |
#find_coupon(code) ⇒ Object
Find coupon by code
101 102 103 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 101 def find_coupon(code) coupon_codes.find { |c| c["code"].upcase == code.upcase } end |
#items ⇒ Object
17 18 19 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 17 def items @items ||= load_json("items")["items"] end |
#items_for_category(category_name) ⇒ Object
61 62 63 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 61 def items_for_category(category_name) items.select { |item| item["category"] == category_name } end |
#line_item_discounts ⇒ Object
Get line-item discounts
76 77 78 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 76 def line_item_discounts discounts.select { |d| d["type"]&.start_with?("line_item") } end |
#loyalty_discounts ⇒ Object
Get loyalty discounts
81 82 83 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 81 def loyalty_discounts discounts_by_type("loyalty") end |
#modifiers ⇒ Object
29 30 31 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 29 def modifiers @modifiers ||= load_json("modifiers")["modifier_groups"] end |
#tax_rates ⇒ Object
Load tax rate definitions
48 49 50 51 52 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 48 def tax_rates @tax_rates ||= load_json("tax_rates")["tax_rates"] rescue Error [] # Return empty array if file doesn't exist end |
#tenders ⇒ Object
25 26 27 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 25 def tenders @tenders ||= load_json("tenders")["tenders"] end |
#threshold_discounts ⇒ Object
Get threshold discounts
86 87 88 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 86 def threshold_discounts discounts_by_type("threshold") end |
#time_based_discounts ⇒ Object
Get time-based discounts
71 72 73 |
# File 'lib/clover_sandbox_simulator/generators/data_loader.rb', line 71 def time_based_discounts discounts_by_type("time_based") end |