Class: FeedMe::FeedParser
Instance Attribute Summary
#feed, #xml
Class Method Summary
collapse
Instance Method Summary
collapse
has_many, has_one, properties, property, #to_hash
Constructor Details
47
48
49
|
# File 'lib/feed_me/feed_parser.rb', line 47
def initialize(xml)
@xml = xml
end
|
Class Method Details
.inherited(subclass) ⇒ Object
16
17
18
19
|
# File 'lib/feed_me/feed_parser.rb', line 16
def inherited(subclass)
super
parsers << subclass
end
|
.open(file) ⇒ Object
21
22
23
|
# File 'lib/feed_me/feed_parser.rb', line 21
def open(file)
self.parse(Kernel.open(file).read)
end
|
.parse(feed) ⇒ Object
parses the passed feed and identifeis what kind of feed it is then returns a parser object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/feed_me/feed_parser.rb', line 27
def parse(feed)
document = Nokogiri::XML(feed)
if root = document.root
root.add_namespace_definition('atom', 'http://www.w3.org/2005/Atom')
root.add_namespace_definition('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
root.add_namespace_definition('rss1', 'http://purl.org/rss/1.0/')
root.add_namespace_definition('dc', 'http://purl.org/dc/elements/1.1/')
parsers.each do |parser|
node = root.xpath(parser.root_node).first
if node
return parser.new(node)
end
end
end
raise InvalidFeedFormat
end
|
.parsers ⇒ Object
12
13
14
|
# File 'lib/feed_me/feed_parser.rb', line 12
def parsers
@parsers ||= []
end
|
.root_node(node = nil) ⇒ Object
7
8
9
10
|
# File 'lib/feed_me/feed_parser.rb', line 7
def root_node(node=nil)
@root_node = node if node
@root_node
end
|