Sha256: 56cebeb82a023431fc02186d2e591b7aca38fb10ba0dc6f40075f666ea4b3bc8
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
require 'cgi' module HentryConsumer class HFeed attr_accessor :html, :entries, :options def initialize(html, options={}) @options = options @html = Nokogiri::HTML(open(html, headers).read) @entries = [] parse_html end def parse_html self.html.css(".h-entry").each do |hentry| entry = HEntry.new(hentry.children) next if entry.older_than(last_modified_at) self.entries << entry end end def to_html self.html.css(".h-entry").collect(&:to_html).join end alias_method :to_s, :to_html def to_hash {:items => [{ :type => ["h-feed"], :properties => { :entries => self.entries } }] } end def to_json(*a) to_hash.to_json(a) end def last_modified_at time = @options[:last_modified_at] || return time = Time.parse(time) if time.is_a? String time.to_time end def headers h = {} h["If-Modified-Since"] = CGI.rfc1123_date(last_modified_at) if last_modified_at h end end end
Version data entries
4 entries across 4 versions & 1 rubygems