Class: Flavordb::ProductCategory
- Defined in:
- lib/flavordb/product_category.rb
Instance Attribute Summary collapse
-
#parent_category_id ⇒ Object
readonly
Returns the value of attribute parent_category_id.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ ProductCategory
constructor
A new instance of ProductCategory.
- #parent_category(opts = {}) ⇒ Object
- #products(opts = {}) ⇒ Object
- #root? ⇒ Boolean
- #subcategories(opts = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ ProductCategory
Returns a new instance of ProductCategory.
14 15 16 17 18 19 20 |
# File 'lib/flavordb/product_category.rb', line 14 def initialize data super @is_root = data['rootCategory'] || false @parent_category_id = data['parentCategoryId'] @products_resource = data['productsResource'] @subcategories_resource = data['subcategoriesResource'] end |
Instance Attribute Details
#parent_category_id ⇒ Object (readonly)
Returns the value of attribute parent_category_id.
5 6 7 |
# File 'lib/flavordb/product_category.rb', line 5 def parent_category_id @parent_category_id end |
Class Method Details
.object_cache ⇒ Object
8 9 10 11 |
# File 'lib/flavordb/product_category.rb', line 8 def object_cache @object_cache = {} if @object_cache.nil? @object_cache end |
Instance Method Details
#parent_category(opts = {}) ⇒ Object
26 27 28 29 |
# File 'lib/flavordb/product_category.rb', line 26 def parent_category(opts = {}) client = opts[:client] || Flavordb::Client.default_client client.get_product_category(parent_category_id) end |
#products(opts = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/flavordb/product_category.rb', line 31 def products(opts = {}) client = opts[:client] || Flavordb::Client.default_client product_data = client.get_object_data_by_path "#{self.resource}/products" product_data['data'].map {|p| Flavordb::Product.get_or_create p} end |
#root? ⇒ Boolean
22 23 24 |
# File 'lib/flavordb/product_category.rb', line 22 def root? @is_root end |
#subcategories(opts = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/flavordb/product_category.rb', line 37 def subcategories(opts = {}) client = opts[:client] || Flavordb::Client.default_client subcategory_data = client.get_object_data_by_path "#{self.resource}/subcategories" subcategory_data['data'].map {|sc| Flavordb::ProductCategory.get_or_create sc} end |