Class: LetsShopMapper::Model::Base::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/letsshop_mapper/model/base/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCategory

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

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/letsshop_mapper/model/base/category.rb', line 7

def children
  @children
end

#filtersObject (readonly)

Returns the value of attribute filters.



8
9
10
# File 'lib/letsshop_mapper/model/base/category.rb', line 8

def filters
  @filters
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/letsshop_mapper/model/base/category.rb', line 5

def id
  @id
end

#nameObject

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_mapObject



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