Class: HentryConsumer::HFeed
- Inherits:
-
Object
- Object
- HentryConsumer::HFeed
- Defined in:
- lib/hentry_consumer/h_feed.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#html ⇒ Object
Returns the value of attribute html.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(html, options = {}) ⇒ HFeed
constructor
A new instance of HFeed.
- #last_modified_at ⇒ Object
- #parse_html ⇒ Object
- #to_hash ⇒ Object
- #to_html ⇒ Object (also: #to_s)
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(html, options = {}) ⇒ HFeed
Returns a new instance of HFeed.
7 8 9 10 11 12 |
# File 'lib/hentry_consumer/h_feed.rb', line 7 def initialize(html, ={}) @options = @html = Nokogiri::HTML(open(html, headers).read) @entries = [] parse_html end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
5 6 7 |
# File 'lib/hentry_consumer/h_feed.rb', line 5 def entries @entries end |
#html ⇒ Object
Returns the value of attribute html.
5 6 7 |
# File 'lib/hentry_consumer/h_feed.rb', line 5 def html @html end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/hentry_consumer/h_feed.rb', line 5 def @options end |
Instance Method Details
#headers ⇒ Object
48 49 50 51 52 |
# File 'lib/hentry_consumer/h_feed.rb', line 48 def headers h = {} h["If-Modified-Since"] = CGI.rfc1123_date(last_modified_at) if last_modified_at h end |
#last_modified_at ⇒ Object
42 43 44 45 46 |
# File 'lib/hentry_consumer/h_feed.rb', line 42 def last_modified_at time = @options[:last_modified_at] || return time = Time.parse(time) if time.is_a? String time.to_time end |
#parse_html ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/hentry_consumer/h_feed.rb', line 14 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 |
#to_hash ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hentry_consumer/h_feed.rb', line 27 def to_hash {:items => [{ :type => ["h-feed"], :properties => { :entries => self.entries } }] } end |
#to_html ⇒ Object Also known as: to_s
22 23 24 |
# File 'lib/hentry_consumer/h_feed.rb', line 22 def to_html self.html.css(".h-entry").collect(&:to_html).join end |
#to_json(*a) ⇒ Object
38 39 40 |
# File 'lib/hentry_consumer/h_feed.rb', line 38 def to_json(*a) to_hash.to_json(a) end |