class Hatenablog::Feed

Attributes

author_name[R]

@dynamic uri, next_uri, title, author_name, updated

next_uri[R]

@dynamic uri, next_uri, title, author_name, updated

title[R]

@dynamic uri, next_uri, title, author_name, updated

updated[R]

@dynamic uri, next_uri, title, author_name, updated

uri[R]

@dynamic uri, next_uri, title, author_name, updated

Public Class Methods

load_xml(xml) click to toggle source

Create a new blog feed from a XML string. @param [String] xml XML string representation @return [Hatenablog::Feed]

# File lib/hatenablog/feed.rb, line 14
def self.load_xml(xml)
  Hatenablog::Feed.new(xml)
end
new(xml) click to toggle source
# File lib/hatenablog/feed.rb, line 38
def initialize(xml)
  @document = Nokogiri::XML(xml)
  parse_document
end

Public Instance Methods

each_entry() { |entry| ... } click to toggle source
# File lib/hatenablog/feed.rb, line 23
def each_entry
  @entries.each do |entry|
    yield entry
  end
end
entries() click to toggle source

@return [Array]

# File lib/hatenablog/feed.rb, line 19
def entries
  @entries.dup
end
has_next?() click to toggle source

Return true if this feed has next feed. @return [Boolean]

# File lib/hatenablog/feed.rb, line 31
def has_next?
  @next_uri != ''
end

Private Instance Methods

parse_document() click to toggle source
# File lib/hatenablog/feed.rb, line 43
def parse_document
  @uri         = @document.at_css("feed link[@rel='alternate']")['href'].to_s
  @next_uri    = if @document.css("feed link[@rel='next']").empty?
                   ''
                 else
                   @document.at_css("feed link[@rel='next']")['href'].to_s
                 end
  @title       = @document.at_css('feed title').content
  @author_name = @document.at_css('author name').content
  @updated     = Time.parse(@document.at_css('feed updated').content)
  parse_entry
end
parse_entry() click to toggle source
# File lib/hatenablog/feed.rb, line 56
def parse_entry
  @entries = @document.css('feed > entry').inject(Array.new) do |entries, entry|
    # add namespace 'app' to recognize XML correctly
    entry['xmlns:app'] = 'http://www.w3.org/2007/app'
    entries << Hatenablog::Entry.load_xml(entry.to_s)
  end
end