Class: AboutYou::SDK::Model::FacetGroupSet
- Inherits:
-
Object
- Object
- AboutYou::SDK::Model::FacetGroupSet
- Defined in:
- lib/AboutYou/Model/facet_group_set.rb
Overview
This class represents a facet group set model
Class Attribute Summary collapse
-
.facet_manager ⇒ Object
instance of AboutYou::SDK::Model::Facet_Manager::DefaultFacetManager.
Instance Attribute Summary collapse
-
#facets ⇒ Object
Array of instances of AboutYou::SDK::Model::Facet.
-
#groups ⇒ Object
Getter for the facet groups of this set.
-
#ids ⇒ Object
Array of ids of the facet groups in this set.
Class Method Summary collapse
-
.merge_facet_ids(facet_ids_array) ⇒ Object
This method merges facet ids in an multi dimensional Array.
Instance Method Summary collapse
-
#contains(facet_compable) ⇒ Object
This method checks whether this set contains a facet or facet group set.
-
#contains_facet_get_group_interface(facet) ⇒ Object
This method checks whether a facet is in this set or not.
-
#contains_facet_group_set(facet_group_set) ⇒ Object
This method checks whether a facet group set is in this set or not.
-
#empty? ⇒ Boolean
This method checks whether this set is empty.
-
#facet(facet_group_id, facet_id) ⇒ Object
This method gets a facet by given facet if and facet group id.
-
#facet_by_key(key) ⇒ Object
This method gets a facet by key.
-
#fetch ⇒ Object
This method fetches the facets of this set.
-
#gen_lazy_groups ⇒ Object
This method is used for generating facet groups for this set.
-
#group(group_id) ⇒ Object
this method is used for getting a group of this set by a group id.
-
#group?(group_id) ⇒ Boolean
this method is used for checking whether a group is in this set or not.
-
#group_ids ⇒ Object
getter for the facet group ids.
-
#initialize(ids) ⇒ FacetGroupSet
constructor
Constructor for the AboutYou::SDK::Model::FacetGroupSet class.
-
#lazy_groups ⇒ Object
Getter for the facet groups of this set.
-
#unique_key ⇒ Object
This method is used for creating a unique key for this facet group set.
Constructor Details
#initialize(ids) ⇒ FacetGroupSet
Constructor for the AboutYou::SDK::Model::FacetGroupSet class
-
Args :
-
ids
-> the ids of the facet groups of this set
-
-
Returns :
-
an instance of AboutYou::SDK::Model::FacetGroupSet
-
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 28 def initialize(ids) self.facets = {} self.groups = {} ids.each do |_key, facet_ids| fail '\InvalidArgumentException! ids must be an associative array of [$groupId => [$facetId,...],..]' unless facet_ids.is_a?(Array) end self.ids = ids self end |
Class Attribute Details
.facet_manager ⇒ Object
instance of AboutYou::SDK::Model::Facet_Manager::DefaultFacetManager
16 17 18 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 16 def facet_manager @facet_manager end |
Instance Attribute Details
#facets ⇒ Object
Array of instances of AboutYou::SDK::Model::Facet
13 14 15 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 13 def facets @facets end |
#groups ⇒ Object
Getter for the facet groups of this set
-
Returns :
-
Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetGroup
-
11 12 13 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 11 def groups @groups end |
#ids ⇒ Object
Array of ids of the facet groups in this set
9 10 11 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 9 def ids @ids end |
Class Method Details
.merge_facet_ids(facet_ids_array) ⇒ Object
This method merges facet ids in an multi dimensional Array
-
Args :
-
facet_ids_array
-> Multi-Dimensional-Array containing facet ids
-
-
Returns :
-
Array of facet ids
-
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 263 def self.merge_facet_ids(facet_ids_array) ids = {} facet_ids_array.each do |facet_ids_hash| facet_ids_hash.each do |group_id, facet_ids| if ids[Integer(group_id)] ids[Integer(group_id)] = ids[Integer(group_id)] + facet_ids.uniq else ids[Integer(group_id)] = facet_ids end end end ids end |
Instance Method Details
#contains(facet_compable) ⇒ Object
This method checks whether this set contains a facet or facet group set
-
Args :
-
facet_compable
-> Facet compable
-
-
Returns :
-
Either nil if wrong input or Boolean determining whether the compable is found or not
-
204 205 206 207 208 209 210 211 212 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 204 def contains(facet_compable) return contains_facet_group_set(facet_compable) if facet_compable.is_a?(self.class) return contains_facet_get_group_interface(facet_compable) if facet_compable.is_a? AboutYou::SDK::Model::FacetGetGroupInterface false end |
#contains_facet_get_group_interface(facet) ⇒ Object
This method checks whether a facet is in this set or not
-
Args :
-
facet
-> Facet compable
-
-
Returns :
-
Boolean determining whether this set includes the facet or not
-
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 223 def contains_facet_get_group_interface(facet) lazy_groups = self.lazy_groups id = facet.group_id if lazy_groups.key?(id) return lazy_groups[id].unique_key == facet.unique_key end false end |
#contains_facet_group_set(facet_group_set) ⇒ Object
This method checks whether a facet group set is in this set or not
-
Args :
-
facet_group_set
-> Facet compable
-
-
Returns :
-
Boolean determining whether this set includes the facet group set or not
-
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 243 def contains_facet_group_set(facet_group_set) return true if unique_key == facet_group_set.unique_key lazy_groups.each do |id, group| return false if lazy_groups['id'] || lazy_groups[id].unique_key != group.unique_key end true end |
#empty? ⇒ Boolean
This method checks whether this set is empty
-
Returns :
-
Boolean determining whether this set is empty or not
-
46 47 48 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 46 def empty? ids.empty? end |
#facet(facet_group_id, facet_id) ⇒ Object
This method gets a facet by given facet if and facet group id
-
Returns :
-
facet_group_id
-> the facet group id used for searching -
facet_id
-> the facet id used for searching
-
-
Returns :
-
Either nil if not found or instance of AboutYou::SDK::Model::Facet
-
175 176 177 178 179 180 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 175 def facet(facet_group_id, facet_id) fetch if facets.empty? return facets[String(facet_group_id) + ':' + String(facet_id)] if facets[String(facet_group_id) + ':' + String(facet_id)] end |
#facet_by_key(key) ⇒ Object
This method gets a facet by key
-
Returns :
-
key
-> the facet key used for searching
-
-
Returns :
-
Either nil if not found or instance of AboutYou::SDK::Model::Facet
-
160 161 162 163 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 160 def facet_by_key(key) fetch facets[key] ? facets[key] : nil end |
#fetch ⇒ Object
This method fetches the facets of this set
-
Returns :
-
Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetGroup
-
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 93 def fetch return unless facets && facets.empty? ids.each do |group_id, facet_ids| facet = self.class.facet_manager.facet(group_id, facet_ids[0]) next unless facet if @groups[group_id] group = @groups[group_id] else group = AboutYou::SDK::Model::FacetGroup.new( group_id, facet.group_name ) @groups[group_id] = group end group.add_facet(facet) facets[facet.unique_key] = facet end end |
#gen_lazy_groups ⇒ Object
This method is used for generating facet groups for this set
-
Returns :
-
Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetGroup
-
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 56 def gen_lazy_groups groups = {} ids.each do |group_id, facet_ids| group = AboutYou::SDK::Model::FacetGroup.new(group_id, nil) facet_ids.each do |facet_id| facet = AboutYou::SDK::Model::Facet.new( facet_id, nil, nil, group_id, nil ) group.add_facet(facet) end groups[group_id] = group end groups end |
#group(group_id) ⇒ Object
this method is used for getting a group of this set by a group id
-
Returns :
-
group_id
-> the group id for which the facet group should be returned
-
-
Returns :
-
Either nil if not found or instance of AboutYou::SDK::Model::FacetGroup
-
134 135 136 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 134 def group(group_id) return groups[group_id] if groups[group_id] end |
#group?(group_id) ⇒ Boolean
this method is used for checking whether a group is in this set or not
-
Returns :
-
group_id
-> the group id used for searching
-
-
Returns :
-
Boolean determining whether this set includes the group_id or not
-
147 148 149 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 147 def group?(group_id) !ids[group_id].empty? end |
#group_ids ⇒ Object
getter for the facet group ids
-
Returns :
-
Array of facet group ids
-
286 287 288 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 286 def group_ids ids.keys end |
#lazy_groups ⇒ Object
Getter for the facet groups of this set
-
Returns :
-
Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetGroup
-
82 83 84 85 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 82 def lazy_groups return @groups unless @groups.empty? gen_lazy_groups end |
#unique_key ⇒ Object
This method is used for creating a unique key for this facet group set
-
Returns :
-
a String containing a unique key for this facet group set
-
188 189 190 191 192 193 |
# File 'lib/AboutYou/Model/facet_group_set.rb', line 188 def unique_key ids.sort! ids.map { |sub_ids| sub_ids.sort! } ids.to_json end |