Class: LetsShopMapper::Model::Base::Category
- Inherits:
-
Object
- Object
- LetsShopMapper::Model::Base::Category
- Defined in:
- lib/letsshop_mapper/model/base/category.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_category(category) ⇒ Object
-
#initialize ⇒ Category
constructor
A new instance of Category.
- #recurse(category, par = nil) ⇒ Object
- #to_map ⇒ Object
- #to_s(localtime = true) ⇒ Object
Constructor Details
#initialize ⇒ Category
Returns a new instance of Category.
10 11 12 13 14 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 10 def initialize() @id, @name = nil @children = [] @filters = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 7 def children @children end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
8 9 10 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 8 def filters @filters end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 6 def name @name end |
Instance Method Details
#add_category(category) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 28 def add_category(category) c = Category::new c.name = category.at("name").text c.id = category.at("name")['id'] return c end |
#recurse(category, par = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 16 def recurse(category, par = nil) category.children.each do |child| if child.name == "category" chl = add_category(child) par.children << chl elsif child.name == "filter" par.filters << Filter::new(child['value']) end recurse(child, chl) end end |
#to_map ⇒ Object
35 36 37 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 35 def to_map {@name => @children.empty? ? nil : @children.map {|child| child.to_map}} end |
#to_s(localtime = true) ⇒ Object
39 40 41 |
# File 'lib/letsshop_mapper/model/base/category.rb', line 39 def to_s(localtime = true) self.to_map.to_yaml end |