Class: AboutYou::SDK::Model::ProductSearchResult
- Inherits:
-
Object
- Object
- AboutYou::SDK::Model::ProductSearchResult
- Defined in:
- lib/AboutYou/Model/product_search_result.rb
Overview
This class represents a product search result model
Instance Attribute Summary collapse
-
#categories ⇒ Object
Array containing instances of AboutYou::SDK::Model::Category.
-
#facets ⇒ Object
Array containing instances of AboutYou::SDK::Model::Facet.
-
#page_hash ⇒ Object
String page hash.
-
#price_ranges ⇒ Object
Array containing instances of AboutYou::SDK::Model::PriceRange.
-
#product_count ⇒ Object
Integer count of products.
-
#products ⇒ Object
Array of instances of AboutYou::SDK::Model::Product.
-
#raw_facets ⇒ Object
raw facets.
-
#sale_counts ⇒ Object
Integer count of products in sale.
Class Method Summary collapse
-
.create_from_json(json_object, factory) ⇒ Object
This method is used for creating an instance of this class by a json_object.
Instance Method Summary collapse
-
#category_tree ⇒ Object
Getter for the category tree.
-
#initialize ⇒ ProductSearchResult
constructor
Constructor for the AboutYou::SDK::Model::ProductSearchResult class.
-
#max_price ⇒ Object
Getter for the max price.
-
#min_price ⇒ Object
Getter for the min price.
-
#parse_facets(json_object, factory) ⇒ Object
This method is used for parsing the facets of the search result.
Constructor Details
#initialize ⇒ ProductSearchResult
Constructor for the AboutYou::SDK::Model::ProductSearchResult class
-
Returns :
-
an instance of AboutYou::SDK::Model::ProductSearchResult
-
31 32 33 34 35 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 31 def initialize self.products = {} self end |
Instance Attribute Details
#categories ⇒ Object
Array containing instances of AboutYou::SDK::Model::Category
21 22 23 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 21 def categories @categories end |
#facets ⇒ Object
Array containing instances of AboutYou::SDK::Model::Facet
19 20 21 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 19 def facets @facets end |
#page_hash ⇒ Object
String page hash
11 12 13 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 11 def page_hash @page_hash end |
#price_ranges ⇒ Object
Array containing instances of AboutYou::SDK::Model::PriceRange
17 18 19 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 17 def price_ranges @price_ranges end |
#product_count ⇒ Object
Integer count of products
13 14 15 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 13 def product_count @product_count end |
#products ⇒ Object
Array of instances of AboutYou::SDK::Model::Product
9 10 11 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 9 def products @products end |
#raw_facets ⇒ Object
raw facets
23 24 25 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 23 def raw_facets @raw_facets end |
#sale_counts ⇒ Object
Integer count of products in sale
15 16 17 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 15 def sale_counts @sale_counts end |
Class Method Details
.create_from_json(json_object, factory) ⇒ 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 -
factory-> instance of AboutYou::SDK::Factory::DefaultModelFactory
-
-
Returns :
-
Instance of AboutYou::SDK::Model::ProductSearchResult
-
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 47 def self.create_from_json(json_object, factory) product_search_result = new product_search_result.page_hash = json_object['page_hash'] product_search_result.product_count = json_object['product_count'] product_search_result.raw_facets = json_object['facets'] json_object['products'].each do |json_product| product = factory.create_product(json_product) product_search_result.products[product.id] = product end product_search_result.parse_facets(json_object['facets'], factory) # free memory json_object['categories'] = nil json_object['prices'] = nil json_object['sale'] = nil product_search_result.facets = factory.create_facets_counts( json_object ) product_search_result end |
Instance Method Details
#category_tree ⇒ Object
Getter for the category tree
-
Returns :
-
/ Array containing instances of AboutYou::SDK::Model::Category
-
133 134 135 136 137 138 139 140 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 133 def category_tree top_level_categories = [] categories.each do |category| top_level_categories.push(category) if category.parent.nil? end top_level_categories end |
#max_price ⇒ Object
Getter for the max price
-
Returns :
-
nil / Integer
-
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 116 def max_price return nil if price_ranges.empty? price_ranges.reverse_each do |price_range| next if price_range.product_count == 0 return price_range.max end price_ranges[-1].max end |
#min_price ⇒ Object
Getter for the min price
-
Returns :
-
nil / Integer
-
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 99 def min_price return nil if price_ranges.empty? price_ranges.each do |price_range| next if price_range.product_count == 0 return price_range.min end price_ranges[0].min end |
#parse_facets(json_object, factory) ⇒ Object
This method is used for parsing the facets of the search result
-
Args :
-
json_object-> the json_object received from the api -
factory-> instance of AboutYou::SDK::Factory::DefaultModelFactory
-
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/AboutYou/Model/product_search_result.rb', line 79 def parse_facets(json_object, factory) self.categories = factory.create_categories_facets( json_object['categories'] ) if json_object['categories'] self.price_ranges = factory.create_price_ranges( json_object['prices'] ) if json_object['prices'] self.sale_counts = factory.create_sale_facet( json_object['sale'] ) if json_object['sale'] end |