Class: FeedMe::AbstractParser
Direct Known Subclasses
Class Attribute Summary collapse
-
.properties ⇒ Object
Returns the value of attribute properties.
-
.root_nodes ⇒ Object
Returns the value of attribute root_nodes.
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#xml ⇒ Object
(also: #root_node)
Returns the value of attribute xml.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml, format) ⇒ AbstractParser
constructor
A new instance of AbstractParser.
- #to_hash ⇒ Object
Constructor Details
#initialize(xml, format) ⇒ AbstractParser
Returns a new instance of AbstractParser.
28 29 30 31 32 33 34 |
# File 'lib/feed_me/abstract_parser.rb', line 28 def initialize(xml, format) self.xml = xml self.format = format self.properties = self.class.properties[self.format] append_methods end |
Class Attribute Details
.properties ⇒ Object
Returns the value of attribute properties.
5 6 7 |
# File 'lib/feed_me/abstract_parser.rb', line 5 def properties @properties end |
.root_nodes ⇒ Object
Returns the value of attribute root_nodes.
5 6 7 |
# File 'lib/feed_me/abstract_parser.rb', line 5 def root_nodes @root_nodes end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
44 45 46 |
# File 'lib/feed_me/abstract_parser.rb', line 44 def format @format end |
#properties ⇒ Object
Returns the value of attribute properties.
44 45 46 |
# File 'lib/feed_me/abstract_parser.rb', line 44 def properties @properties end |
#xml ⇒ Object Also known as: root_node
Returns the value of attribute xml.
44 45 46 |
# File 'lib/feed_me/abstract_parser.rb', line 44 def xml @xml end |
Class Method Details
.build(xml, format, *args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/feed_me/abstract_parser.rb', line 7 def build(xml, format, *args) # in a world with activesupport this would have been written as # format_parser = (format.to_s.camelize + self.to_s).constantize camelized_format = format.to_s.split('_').map{ |w| w.capitalize }.join('') = self.to_s.split('::').last begin format_parser = FeedMe.const_get(camelized_format + ) rescue NameError end if format_parser.is_a?(Class) and format_parser.ancestors.include?(self) return format_parser.new(xml, format, *args) else return self.new(xml, format, *args) end end |
Instance Method Details
#to_hash ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/feed_me/abstract_parser.rb', line 36 def to_hash hash = {} self.properties.each do |method, p| hash[method] = self.send(method) end return hash end |