Class: FeedMe::AbstractParser
- Inherits:
-
Object
- Object
- FeedMe::AbstractParser
show all
- Defined in:
- lib/feed_me/abstract_parser.rb
Instance Attribute Summary collapse
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
-
#xml ⇒ Object
(also: #root_node)
readonly
Returns the value of attribute xml.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
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
#feed ⇒ Object
Returns the value of attribute feed.
61
62
63
|
# File 'lib/feed_me/abstract_parser.rb', line 61
def feed
@feed
end
|
#xml ⇒ Object
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
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
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
|
.properties ⇒ Object
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_hash ⇒ Object
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
|