Class: Genit::RssFeedItemTitle

Inherits:
Object
  • Object
show all
Defined in:
lib/genit/project/rss_feed.rb

Overview

Retrieve the title element of an item element of an RSS feed from a news article.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(news_pathname) ⇒ RssFeedItemTitle

Returns a new instance of RssFeedItemTitle.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/genit/project/rss_feed.rb', line 82

def initialize news_pathname
  @news_pathname = news_pathname
  @title = NewsUtils.get_date_from_filename @news_pathname
  doc = HtmlDocument.open_fragment(@news_pathname)
  ('h1'..'h6').each do |header|
    tag = doc.at_css(header)
    if tag
      @title = tag.inner_html
      break
    end
  end
end

Instance Attribute Details

#titleObject (readonly)

Public: Get the first title content from a news article.

We first search for <h1> header level, then <h2>, etc to <h6>. If the news article doesn’t contains any <h*> element, the title() method returns the ISO date string (yyyy-mm-dd) found in the news article pathname.

Returns the String title of the news article.



80
81
82
# File 'lib/genit/project/rss_feed.rb', line 80

def title
  @title
end