Class: LetsShopMapper::Model::Tree::Tree
- Inherits:
-
Object
- Object
- LetsShopMapper::Model::Tree::Tree
- Defined in:
- lib/letsshop_mapper/model/tree/tree.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#initialize(tree = nil) ⇒ Tree
constructor
A new instance of Tree.
- #parse(tree) ⇒ Object
- #to_s(localtime = true) ⇒ Object
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
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
5 6 7 |
# File 'lib/letsshop_mapper/model/tree/tree.rb', line 5 def categories @categories end |
#xml ⇒ Object (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 |