Class: AboutYou::SDK::Model::Autocomplete
- Inherits:
-
Object
- Object
- AboutYou::SDK::Model::Autocomplete
- Defined in:
- lib/AboutYou/Model/autocomplete.rb
Overview
This Class represents an autocomplete model
Constant Summary collapse
- NOT_REQUESTED =
this constant is used for values which are not requested
nil- TYPE_PRODUCTS =
argument for api when requiring products
'products'- TYPE_CATEGORIES =
argument for api when requiring categories
'categories'- TYPE_BRANDS =
argument for api when requiring brands
'brands'
Instance Attribute Summary collapse
-
#brands ⇒ Object
the brands of the autocomplete.
-
#categories ⇒ Object
the categories of the autocomplete.
-
#products ⇒ Object
the products of the autocomplete.
Class Method Summary collapse
-
.create_from_json(json_object, factory) ⇒ Object
This method lets you build an autocomplete model by a json response from the api.
-
.parse_brands(json_object, factory) ⇒ Object
This method parses the json object and builds product models from it.
-
.parse_categories(json_object, factory) ⇒ Object
This method parses the json object and builds category models from it.
-
.parse_products(json_object, factory) ⇒ Object
This method parses the json object and builds product models from it.
Instance Method Summary collapse
-
#initialize(categories = nil, products = nil, brands = nil) ⇒ Autocomplete
constructor
the Constructor for the autocomplete class.
Constructor Details
#initialize(categories = nil, products = nil, brands = nil) ⇒ Autocomplete
the Constructor for the autocomplete class
-
Args :
-
categories-> the products of the autocomplete -
products-> the categories of the autocomplete -
brands-> the brands of the autocomplete
-
-
Returns :
-
Instance of AboutYou::SDK::Model::AutoComplete
-
35 36 37 38 39 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 35 def initialize(categories = nil, products = nil, brands = nil) self.categories = categories self.products = products self.brands = brands end |
Instance Attribute Details
#brands ⇒ Object
the brands of the autocomplete
22 23 24 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 22 def brands @brands end |
#categories ⇒ Object
the categories of the autocomplete
20 21 22 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 20 def categories @categories end |
#products ⇒ Object
the products of the autocomplete
18 19 20 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 18 def products @products end |
Class Method Details
.create_from_json(json_object, factory) ⇒ Object
This method lets you build an autocomplete model by a json response from the api
-
Args :
-
json_object-> the json response from the api -
factory-> the model factory responsible for building the models
-
-
Returns :
-
Instance of AboutYou::SDK::Model::AutoComplete
-
51 52 53 54 55 56 57 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 51 def self.create_from_json(json_object, factory) new( parse_categories(json_object, factory), parse_products(json_object, factory), parse_brands(json_object, factory) ) end |
.parse_brands(json_object, factory) ⇒ Object
This method parses the json object and builds product models from it
-
Args :
-
json_object-> the json response from the api -
factory-> the model factory responsible for building the models
-
-
Returns :
-
Array containing instances of AboutYou::SDK::Model::Product
-
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 113 def self.parse_brands(json_object, factory) return NOT_REQUESTED unless json_object.key?('brands') return [] if json_object['brands'].nil? brands = [] json_object['brands'].each do |brand| brands.push(factory.create_brand(brand)) end brands end |
.parse_categories(json_object, factory) ⇒ Object
This method parses the json object and builds category models from it
-
Args :
-
json_object-> the json response from the api -
factory-> the model factory responsible for building the models
-
-
Returns :
-
Array containing instances of AboutYou::SDK::Model::Category
-
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 69 def self.parse_categories(json_object, factory) return NOT_REQUESTED unless json_object.key?('categories') return [] if json_object['categories'].nil? categories = [] json_object['categories'].each do |category| categories.push(factory.create_category(category)) end categories end |
.parse_products(json_object, factory) ⇒ Object
This method parses the json object and builds product models from it
-
Args :
-
json_object-> the json response from the api -
factory-> the model factory responsible for building the models
-
-
Returns :
-
Array containing instances of AboutYou::SDK::Model::Product
-
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/AboutYou/Model/autocomplete.rb', line 91 def self.parse_products(json_object, factory) return NOT_REQUESTED unless json_object.key?('products') return [] if json_object['products'].nil? products = [] json_object['products'].each do |product| products.push(factory.create_product(product)) end products end |