Class: Feedcellar::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/feedcellar/feed.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, link, description, date) ⇒ Feed

Returns a new instance of Feed.



24
25
26
27
28
29
# File 'lib/feedcellar/feed.rb', line 24

def initialize(title, link, description, date)
  @title = title
  @link = link
  @description = description
  @date = date
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



23
24
25
# File 'lib/feedcellar/feed.rb', line 23

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



23
24
25
# File 'lib/feedcellar/feed.rb', line 23

def description
  @description
end

Returns the value of attribute link.



23
24
25
# File 'lib/feedcellar/feed.rb', line 23

def link
  @link
end

#titleObject (readonly)

Returns the value of attribute title.



23
24
25
# File 'lib/feedcellar/feed.rb', line 23

def title
  @title
end

Class Method Details

.parse(feed_url) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/feedcellar/feed.rb', line 31

def self.parse(feed_url)
  feeds = []

  begin
    rss = Feedjira::Feed.fetch_and_parse(feed_url)
  rescue
    $stderr.puts "WARNING: #{$!} (#{feed_url})"
    return nil
  end
  return nil unless rss

  rss.entries.each do |entry|
    title = entry.title
    link = entry.url
    description = entry.summary || entry.content
    date = entry.published || entry.updated

    next unless link

    feeds << new(title, link, description, date)
  end

  feeds
end