Class: NewsFetcher::Item
- Inherits:
-
Object
- Object
- NewsFetcher::Item
- Includes:
- SetParams, Simple::Printer::Printable
- Defined in:
- lib/newsfetcher/item.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#content ⇒ Object
Returns the value of attribute content.
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #age ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(entry) ⇒ Item
constructor
A new instance of Item.
- #printable ⇒ Object
Constructor Details
#initialize(entry) ⇒ Item
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/newsfetcher/item.rb', line 15 def initialize(entry) if entry.url begin uri = Addressable::URI.parse(entry.url.strip) rescue Addressable::URI::InvalidURIError => e raise Error, "Can't parse URL for entry: #{entry.url.inspect}" end else uri = nil end id = entry.entry_id || uri or raise Error, "Can't determine ID or URL for entry" super( id: id.to_s, uri: uri, date: entry.published || Time.now, title: entry.title, author: entry.respond_to?(:author) ? entry.&.sub(/^by\s+/i, '') : nil, content: (entry.content || entry.summary)&.to_s, ) end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
9 10 11 |
# File 'lib/newsfetcher/item.rb', line 9 def @author end |
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'lib/newsfetcher/item.rb', line 10 def content @content end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/newsfetcher/item.rb', line 6 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/newsfetcher/item.rb', line 5 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/newsfetcher/item.rb', line 7 def title @title end |
#uri ⇒ Object
Returns the value of attribute uri.
8 9 10 |
# File 'lib/newsfetcher/item.rb', line 8 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/newsfetcher/item.rb', line 50 def ==(other) @id == other&.id end |
#age ⇒ Object
54 55 56 |
# File 'lib/newsfetcher/item.rb', line 54 def age Time.now - @date end |
#eql?(other) ⇒ Boolean
46 47 48 |
# File 'lib/newsfetcher/item.rb', line 46 def eql?(other) @id.eql?(other.id) end |
#printable ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/newsfetcher/item.rb', line 36 def printable [ [:id, 'ID'], :date, :title, :uri, :author, ] end |