Class: AboutYou::SDK::Model::Category
- Inherits:
-
Object
- Object
- AboutYou::SDK::Model::Category
- Defined in:
- lib/AboutYou/Model/category.rb
Overview
This class represents a category model
Constant Summary collapse
- ALL =
all categories
false
- ACTIVE_ONLY =
only active categories
true
Instance Attribute Summary collapse
-
#active_subcategories ⇒ Object
Array containing all active subcategories.
-
#all_subcategories ⇒ Object
Array containing all subcategories.
-
#category_manager ⇒ Object
instance of AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.
-
#id ⇒ Object
id of the category.
-
#is_active ⇒ Object
boolean determining whether the category is active.
-
#name ⇒ Object
name of the category.
-
#parent_id ⇒ Object
id of the parent category.
-
#position ⇒ Object
position of the category.
-
#product_count ⇒ Object
count of products in category.
Class Method Summary collapse
-
.create_from_json(json_object, cat_manager) ⇒ Object
This method is used for creating an instance of this class by a json_object.
Instance Method Summary collapse
-
#breadcrumb ⇒ Object
This method is used for getting the breadcrumb up to this category.
-
#initialize ⇒ Category
constructor
Constructor for the AboutYou::SDK::Model::Category class.
-
#parent ⇒ Object
This method returns the parent category.
-
#path_active? ⇒ Boolean
This method checks if the complete category path up to this category is active.
-
#subcategories(active_only = ACTIVE_ONLY) ⇒ Object
This method is used for getting all subcategories.
Constructor Details
#initialize ⇒ Category
Constructor for the AboutYou::SDK::Model::Category class
-
Returns :
-
an instance of AboutYou::SDK::Model::Category
-
38 39 40 41 42 43 |
# File 'lib/AboutYou/Model/category.rb', line 38 def initialize self.all_subcategories = [] self.active_subcategories = [] self end |
Instance Attribute Details
#active_subcategories ⇒ Object
Array containing all active subcategories
26 27 28 |
# File 'lib/AboutYou/Model/category.rb', line 26 def active_subcategories @active_subcategories end |
#all_subcategories ⇒ Object
Array containing all subcategories
24 25 26 |
# File 'lib/AboutYou/Model/category.rb', line 24 def all_subcategories @all_subcategories end |
#category_manager ⇒ Object
instance of AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager
30 31 32 |
# File 'lib/AboutYou/Model/category.rb', line 30 def category_manager @category_manager end |
#id ⇒ Object
id of the category
14 15 16 |
# File 'lib/AboutYou/Model/category.rb', line 14 def id @id end |
#is_active ⇒ Object
boolean determining whether the category is active
18 19 20 |
# File 'lib/AboutYou/Model/category.rb', line 18 def is_active @is_active end |
#name ⇒ Object
name of the category
16 17 18 |
# File 'lib/AboutYou/Model/category.rb', line 16 def name @name end |
#parent_id ⇒ Object
id of the parent category
22 23 24 |
# File 'lib/AboutYou/Model/category.rb', line 22 def parent_id @parent_id end |
#position ⇒ Object
position of the category
20 21 22 |
# File 'lib/AboutYou/Model/category.rb', line 20 def position @position end |
#product_count ⇒ Object
count of products in category
28 29 30 |
# File 'lib/AboutYou/Model/category.rb', line 28 def product_count @product_count end |
Class Method Details
.create_from_json(json_object, cat_manager) ⇒ Object
This method is used for creating an instance of this class by a json_object.
-
Args :
-
json_object
-> the json_object received from the api -
cat_manager
-> instance of AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager
-
-
Returns :
-
Instance of AboutYou::SDK::Model::Category
-
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/AboutYou/Model/category.rb', line 55 def self.create_from_json(json_object, cat_manager) category = new category.parent_id = json_object['parent'] category.id = json_object['id'] category.name = json_object['name'] category.is_active = json_object['active'] category.position = json_object['position'] category.category_manager = cat_manager category end |
Instance Method Details
#breadcrumb ⇒ Object
This method is used for getting the breadcrumb up to this category
-
Returns :
-
Array containing instances of AboutYou::SDK::Model::Category
-
119 120 121 122 123 124 |
# File 'lib/AboutYou/Model/category.rb', line 119 def = parent ? parent. : [] .push(self) end |
#parent ⇒ Object
This method returns the parent category
-
Returns :
-
Either instance of AboutYou::SDK::Model::Category or nil if no parent category is set
-
85 86 87 88 89 |
# File 'lib/AboutYou/Model/category.rb', line 85 def parent return nil unless parent_id category_manager.category(parent_id) end |
#path_active? ⇒ Boolean
This method checks if the complete category path up to this category is active
-
Returns :
-
Boolean determining whether the complete path up to this category is active or not
-
75 76 77 |
# File 'lib/AboutYou/Model/category.rb', line 75 def path_active? is_active && (parent.nil? || parent.path_active?) end |
#subcategories(active_only = ACTIVE_ONLY) ⇒ Object
This method is used for getting all subcategories
-
Args :
-
active_only
-> boolean controlling whether the result should only contain active categories or not
-
-
Returns :
-
Hash containing pairs of category_id => instance of AboutYou::SDK::Model::Category
-
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/AboutYou/Model/category.rb', line 100 def subcategories(active_only = ACTIVE_ONLY) subcategories = category_manager.subcategories(id, active_only) return subcategories if active_only == ALL result = {} subcategories.each do |key, subcat| result[key] = subcat if subcat.is_active end result end |