class Feed2Email::FeedAutodiscoverer

Public Class Methods

new(uri) click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 7
def initialize(uri)
  @uri = uri
end

Public Instance Methods

content_type() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 11
def content_type; handle.content_type end
feeds() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 13
def feeds
  @feeds ||= discoverable? ? discover : []
end

Private Instance Methods

data() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 19
def data; handle.read end
discover() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 21
def discover
  head = Nokogiri::HTML(data).at_css('head')

  if base = head.at_css('base[href]')
    base_uri = base['href']
  else
    base_uri = handle.base_uri.to_s
  end

  head.css('link[rel=alternate]').select {|link|
    link['href'] && link['type'] =~ /\Aapplication\/(rss|atom)\+xml\z/
  }.map do |link|
    if link['href'] =~ %r{\Ahttps?://} # absolute
      uri = link['href']
    else
      uri = URI.join(base_uri, link['href']).to_s # relative
    end

    { uri: uri, content_type: link['type'], title: link['title'] }
  end
end
discoverable?() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 43
def discoverable?
  handle.content_type == 'text/html'
end
handle() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 47
def handle
  @handle ||= open(uri)
end
uri() click to toggle source
# File lib/feed2email/feed_autodiscoverer.rb, line 51
def uri; @uri end