Class: Spix::FeedDiscovery::Document
- Defined in:
- lib/spix_parser/tools/feed_discovery/document.rb
Instance Method Summary collapse
- #feed? ⇒ Boolean
- #feed_exception_from(error, &block) ⇒ Object
- #feed_uris(&block) ⇒ Object
- #feeds(&block) ⇒ Object
- #html? ⇒ Boolean
-
#initialize(uri_name) ⇒ Document
constructor
A new instance of Document.
- #load_content ⇒ Object
- #parse_uri(path) ⇒ Object
Constructor Details
#initialize(uri_name) ⇒ Document
Returns a new instance of Document.
5 6 7 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 5 def initialize uri_name @uri = parse_uri uri_name end |
Instance Method Details
#feed? ⇒ Boolean
165 166 167 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 165 def feed? %w[rss feed].include? @document.root.name end |
#feed_exception_from(error, &block) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 53 def feed_exception_from error, &block Feed.new(@uri).tap { |item| item.exceptions = [error.to_s] block.call item if block_given? } end |
#feed_uris(&block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 29 def feed_uris &block items = [] load_content items = uris_from_links(&block) + uris_from_anchors(&block) items << Feed.new(@uri).tap { |uri| block.call uri if block_given? } if feed? rescue => error items << feed_exception_from(error) ensure return items end |
#feeds(&block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 42 def feeds &block items = [] load_content items = feeds_from_links(&block) + feeds_from_anchors(&block) items << feed_unsing_address(@uri, &block) if feed? rescue => error items << feed_exception_from(error) ensure return items end |
#html? ⇒ Boolean
161 162 163 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 161 def html? @document.root.name == "html" end |
#load_content ⇒ Object
9 10 11 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 9 def load_content @document ||= content_from @uri.to_s end |
#parse_uri(path) ⇒ Object
169 170 171 |
# File 'lib/spix_parser/tools/feed_discovery/document.rb', line 169 def parse_uri path URI.parse URI.encode path.to_s end |