Class: Rssly::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/rssly/article.rb

Overview

Represents a single rss article

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, url: nil, published: nil, summary: nil, topics: nil) ⇒ Article

Returns a new instance of Article.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rssly/article.rb', line 22

def initialize(title: nil,
               url: nil,
               published: nil,
               summary: nil,
               topics: nil)
  self.title = title
  self.url = url
  self.published = published
  self.summary = summary
  self.topics = topics
end

Instance Attribute Details

#publishedObject

Returns the value of attribute published.



20
21
22
# File 'lib/rssly/article.rb', line 20

def published
  @published
end

#summaryObject

Returns the value of attribute summary.



18
19
20
# File 'lib/rssly/article.rb', line 18

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/rssly/article.rb', line 16

def title
  @title
end

#topicsObject

Returns the value of attribute topics.



19
20
21
# File 'lib/rssly/article.rb', line 19

def topics
  @topics
end

#urlObject

Returns the value of attribute url.



17
18
19
# File 'lib/rssly/article.rb', line 17

def url
  @url
end

Class Method Details

.create_from_feedjira_entry(entry) ⇒ Object



11
12
13
# File 'lib/rssly/article.rb', line 11

def create_from_feedjira_entry(entry)
  new(title: entry.title, url: entry.url, published: entry.published)
end

Instance Method Details

#extractedObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rssly/article.rb', line 75

def extracted
  @extracted ||= begin
    $stderr.puts "Fetching article at #{url}" if Rssly::CONFIG[:verbose]
    source = open(url, allow_redirections: :all).read
    Readability::Document.new(source)
  end
rescue
  raise \
  Rssly::HTTPError,
  "Could not retrieve document for article at: #{url}"
end

#summarizedObject



67
68
69
70
71
72
73
# File 'lib/rssly/article.rb', line 67

def summarized
  @summarized ||= begin
    $stderr.puts "Summarizing article at #{url}" if Rssly::CONFIG[:verbose]
    text = extracted.content.gsub(/<\/?[^>]*>/, '')
    OTS.parse(text)
  end
end

#to_hObject



59
60
61
62
63
64
65
# File 'lib/rssly/article.rb', line 59

def to_h
  { title: title,
    url: url,
    summary: summary,
    topics: topics,
    published: published }
end