Class
Class Methods
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 92
def boolean_argument(positioned_value, option_value, default)
value = positioned_value
if value.nil? and not option_value.nil?
value = option_value
end
value = default if value.nil?
value
end
No documentation available
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 61
def default_parser
@@default_parser || AVAILABLE_PARSERS.first
end
No documentation available
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 67
def default_parser=(new_value)
if AVAILABLE_PARSERS.include?(new_value)
@@default_parser = new_value
else
raise NotValidXMLParser.new(new_value)
end
end
Set
@@default_parser to new_value if it is one of the available parsers. Else raise NotValidXMLParser
error.
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 107
def initialize(rss, parser_class=self.class.default_parser)
@parser = parser_class.new(normalize_rss(rss))
end
No documentation available
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 75
def parse(rss, *args)
if args.last.is_a?(Hash)
options = args.pop
else
options = {}
end
do_validate = boolean_argument(args[0], options[:validate], true)
ignore_unknown_element =
boolean_argument(args[1], options[:ignore_unknown_element], true)
parser_class = args[2] || options[:parser_class] || default_parser
parser = new(rss, parser_class)
parser.do_validate = do_validate
parser.ignore_unknown_element = ignore_unknown_element
parser.parse
end
No documentation available
Instance Methods
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 131
def maybe_xml?(source)
source.is_a?(String) and /</ =~ source
end
maybe_xml? tests if source is a string that looks like XML
.
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 116
def normalize_rss(rss)
return rss if maybe_xml?(rss)
uri = to_uri(rss)
if uri.respond_to?(:read)
uri.read
elsif !rss.tainted? and File.readable?(rss)
File.open(rss) {|f| f.read}
else
rss
end
end
lib/rss/parser.rb
View on GitHub
# File tmp/rubies/ruby-2.6.10/lib/rss/parser.rb, line 137
def to_uri(rss)
return rss if rss.is_a?(::URI::Generic)
begin
::URI.parse(rss)
rescue ::URI::Error
rss
end
end
Attempt to convert rss to a URI
, but just return it if there’s a ::URI::Error