Class: AmazonProductTypeSchema
- Inherits:
-
Object
- Object
- AmazonProductTypeSchema
- Defined in:
- app/models/amazon_product_type_schema.rb
Constant Summary collapse
- BASE_PATH =
File.join('data', 'json', 'schemas', 'amazon_sc', 'product_type').to_s.freeze
Class Method Summary collapse
- .all_product_type_theme_names ⇒ Object
- .available_product_types ⇒ Object
- .available_schemas_path ⇒ Object
- .load_product_type_schema_as_json(schema_name) ⇒ Object
- .product_type_theme_names_hash ⇒ Object
Class Method Details
.all_product_type_theme_names ⇒ Object
24 25 26 |
# File 'app/models/amazon_product_type_schema.rb', line 24 def all_product_type_theme_names product_type_theme_names_hash.values.flatten.uniq.compact.sort end |
.available_product_types ⇒ Object
8 9 10 |
# File 'app/models/amazon_product_type_schema.rb', line 8 def available_product_types available_schemas_path.map { |fp| File.basename(fp, '.json').upcase } end |
.available_schemas_path ⇒ Object
4 5 6 |
# File 'app/models/amazon_product_type_schema.rb', line 4 def available_schemas_path Dir.glob(File.join(BASE_PATH, '*.json')) end |
.load_product_type_schema_as_json(schema_name) ⇒ Object
12 13 14 15 |
# File 'app/models/amazon_product_type_schema.rb', line 12 def load_product_type_schema_as_json(schema_name) schema_path = File.join(BASE_PATH, "#{schema_name.downcase}.json") JSON.parse(File.read(schema_path)) end |
.product_type_theme_names_hash ⇒ Object
17 18 19 20 21 22 |
# File 'app/models/amazon_product_type_schema.rb', line 17 def product_type_theme_names_hash available_product_types.each_with_object({}) do |product_type, hsh| theme_names = load_product_type_schema_as_json(product_type).dig('properties', 'variation_theme', 'items', 'properties', 'name', 'enum') hsh[product_type] = theme_names end end |