Class: FeedMe::AbstractParser

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_me/abstract_parser.rb

Direct Known Subclasses

FeedParser, ItemParser, PersonParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed, xml) ⇒ AbstractParser

Returns a new instance of AbstractParser.



48
49
50
51
# File 'lib/feed_me/abstract_parser.rb', line 48

def initialize(feed, xml)
  @xml = xml
  @feed = feed
end

Instance Attribute Details

#feedObject (readonly)

Returns the value of attribute feed.



61
62
63
# File 'lib/feed_me/abstract_parser.rb', line 61

def feed
  @feed
end

#xmlObject (readonly) Also known as: root_node

Returns the value of attribute xml.



61
62
63
# File 'lib/feed_me/abstract_parser.rb', line 61

def xml
  @xml
end

Class Method Details

.has_many(name, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/feed_me/abstract_parser.rb', line 20

def has_many(name, options={})
  raise ArgumentError, "must specify :use option" unless options[:use]
  options[:path] ||= name
  options[:association] = :has_many
  properties[name.to_sym] = options

  class_eval <<-RUBY, __FILE__, __LINE__+1
    def #{name}
      get_has_many_association(:#{name})
    end
  RUBY
end

.has_one(name, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/feed_me/abstract_parser.rb', line 33

def has_one(name, options={})
  raise ArgumentError, "must specify :use option" unless options[:use]
  options[:path] ||= name
  options[:association] = :has_one
  properties[name.to_sym] = options

  class_eval <<-RUBY, __FILE__, __LINE__+1
    def #{name}
      get_has_one_association(:#{name})
    end
  RUBY
end

.propertiesObject



5
6
7
# File 'lib/feed_me/abstract_parser.rb', line 5

def properties
  @properties ||= {}
end

.property(name, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/feed_me/abstract_parser.rb', line 9

def property(name, options={})
  options[:path] ||= name
  properties[name.to_sym] = options

  class_eval <<-RUBY, __FILE__, __LINE__+1
    def #{name}
      get_property(:#{name})
    end
  RUBY
end

Instance Method Details

#to_hashObject



53
54
55
56
57
58
59
# File 'lib/feed_me/abstract_parser.rb', line 53

def to_hash
  hash = {}
  self.class.properties.each do |method, p|
    hash[method] = self.send(method)
  end
  return hash
end