Class: EndiFeed::News

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/endi_feed/news.rb

Overview

This class cleans up and formats XML/RSS feed.

Instance Method Summary collapse

Methods included from Util

convert_date, convert_time, included, parse_feed

Constructor Details

#initializeNews

Loads initial data

sets @headlines ivar
and calls :news_feed, :channel methods

See Also:



15
16
17
18
19
# File 'lib/endi_feed/news.rb', line 15

def initialize
  @headlines = []
  news_feed
  channel
end

Instance Method Details

#channelObject

Convenience method for feed channel



46
47
48
# File 'lib/endi_feed/news.rb', line 46

def channel
  @channel ||= @news_feed.channel
end

#format_header_text(headlines) ⇒ Array<String>

Applies formatting to header text



75
76
77
78
79
# File 'lib/endi_feed/news.rb', line 75

def format_header_text(headlines)
  sub_title    = "Última actualización: #{ last_update }"
  header_title = "#{ title } (#{ site_url })"
  headlines.unshift(header_title, sub_title)
end

#get_headlines(total) ⇒ Array<String>

Factory method that gets the news

See Also:



30
31
32
33
34
35
# File 'lib/endi_feed/news.rb', line 30

def get_headlines(total)
  process_news(total)
  format_header_text(@headlines)
rescue
  'Problem retrieving news headlines.'
end

#itemsObject

Convenience method for items in feed



51
52
53
# File 'lib/endi_feed/news.rb', line 51

def items
  @news_feed.items
end

#last_updateString

Returns the last update time of the feed



69
70
71
# File 'lib/endi_feed/news.rb', line 69

def last_update
  convert_time(@channel.pubDate)
end

#news_feedRSS

Loads news into instance variable

@see EndiFeed::Util.parse_feed


41
42
43
# File 'lib/endi_feed/news.rb', line 41

def news_feed
  @news_feed ||= parse_feed
end

#site_urlString

Returns the site’s url from the feed



63
64
65
# File 'lib/endi_feed/news.rb', line 63

def site_url
  @channel.link
end

#titleString

Returns the title from the feed



57
58
59
# File 'lib/endi_feed/news.rb', line 57

def title
  @channel.title
end