Class: LetsShopMapper::Model::Tree::Tree

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree = nil) ⇒ Tree

Returns a new instance of Tree.



8
9
10
11
# File 'lib/letsshop_mapper/model/tree/tree.rb', line 8

def initialize(tree = nil)
  @categories = []
  parse(tree) if tree
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



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

def categories
  @categories
end

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/letsshop_mapper/model/tree/tree.rb', line 6

def xml
  @xml
end

Instance Method Details

#parse(tree) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/letsshop_mapper/model/tree/tree.rb', line 13

def parse(tree)
  @xml = Nokogiri::XML(tree)
  if @xml.at('/categories')
    @xml.xpath('/categories/category').each do |c|
      @categories = Base::Category::new
      @categories.recurse(c, @categories)
    end
  elsif @xml.at('/category')
    @xml.xpath('/category').each do |c|
      @categories = Base::Category::new
      @categories.recurse(c, @categories)
    end            
  else
    raise LetsShopMapper::Error::UnknownFeedTypeException::new
  end
end

#to_s(localtime = true) ⇒ Object



30
31
32
# File 'lib/letsshop_mapper/model/tree/tree.rb', line 30

def to_s(localtime = true)
  s = @categories.to_s(localtime)
end