Class: EndiFeed::News
Overview
This class cleans up and formats XML/RSS feed.
Instance Method Summary collapse
-
#channel ⇒ Object
Convenience method for feed channel.
-
#format_header_text(headlines) ⇒ Array<String>
Applies formatting to header text.
-
#get_headlines(total) ⇒ Array<String>
Factory method that gets the news.
-
#initialize ⇒ News
constructor
Loads initial data sets @headlines ivar and calls :news_feed, :channel methods.
-
#items ⇒ Object
Convenience method for items in feed.
-
#last_update ⇒ String
Returns the last update time of the feed.
-
#news_feed ⇒ RSS
Loads news into instance variable.
-
#site_url ⇒ String
Returns the site’s url from the feed.
-
#title ⇒ String
Returns the title from the feed.
Methods included from Util
convert_date, convert_time, included, parse_feed
Constructor Details
#initialize ⇒ News
Loads initial data
sets @headlines ivar
and calls :news_feed, :channel methods
15 16 17 18 19 |
# File 'lib/endi_feed/news.rb', line 15 def initialize @headlines = [] news_feed channel end |
Instance Method Details
#channel ⇒ Object
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
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 |
#items ⇒ Object
Convenience method for items in feed
51 52 53 |
# File 'lib/endi_feed/news.rb', line 51 def items @news_feed.items end |
#last_update ⇒ String
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_feed ⇒ RSS
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_url ⇒ String
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 |
#title ⇒ String
Returns the title from the feed
57 58 59 |
# File 'lib/endi_feed/news.rb', line 57 def title @channel.title end |