class FeedNormalizer::Parser
The root parser object. Every parser must extend this object.
Public Class Methods
parse(feed, loose)
click to toggle source
Parses the given feed, and returns a normalized representation. Returns nil if the feed could not be parsed.
# File lib/feed-normalizer.rb, line 16 def self.parse(feed, loose) nil end
parser()
click to toggle source
Parser being used.
# File lib/feed-normalizer.rb, line 10 def self.parser nil end
priority()
click to toggle source
Returns a number to indicate parser priority. The lower the number, the more likely the parser will be used first, and vice-versa.
# File lib/feed-normalizer.rb, line 23 def self.priority 0 end
Protected Class Methods
append_or_set!(value, object, object_function)
click to toggle source
# File lib/feed-normalizer.rb, line 53 def self.append_or_set!(value, object, object_function) if object.send(object_function).respond_to? :push object.send(object_function).push(value) else object.send(:"#{object_function}=", value) end end
map_functions!(mapping, src, dest)
click to toggle source
sets value, or appends to an existing value
# File lib/feed-normalizer.rb, line 32 def self.map_functions!(mapping, src, dest) mapping.each do |dest_function, src_functions| src_functions = [src_functions].flatten # pack into array src_functions.each do |src_function| value = if src.respond_to?(src_function) src.send(src_function) elsif src.respond_to?(:has_key?) src[src_function] end unless value.to_s.empty? append_or_set!(value, dest, dest_function) break end end end end
Private Class Methods
inherited(subclass)
click to toggle source
Callback that ensures that every parser gets registered.
# File lib/feed-normalizer.rb, line 64 def self.inherited(subclass) ParserRegistry.register(subclass) end