Class: BbcNewsCliGem::Article
- Inherits:
-
Object
- Object
- BbcNewsCliGem::Article
- Defined in:
- lib/bbc_news_cli_gem/article.rb
Instance Attribute Summary collapse
-
#intro ⇒ Object
Returns the value of attribute intro.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#web_page ⇒ Object
readonly
Returns the value of attribute web_page.
Instance Method Summary collapse
- #add_to_web_page(web_page) ⇒ Object
- #display ⇒ Object
-
#initialize(web_page, title, link) ⇒ Article
constructor
A new instance of Article.
- #open ⇒ Object
- #uniq_title ⇒ Object
- #valid_title_and_link ⇒ Object
Constructor Details
#initialize(web_page, title, link) ⇒ Article
Returns a new instance of Article.
6 7 8 9 10 11 12 |
# File 'lib/bbc_news_cli_gem/article.rb', line 6 def initialize(web_page, title, link) @title = title @link = link @web_page = web_page add_to_web_page(web_page) if valid_title_and_link self end |
Instance Attribute Details
#intro ⇒ Object
Returns the value of attribute intro.
4 5 6 |
# File 'lib/bbc_news_cli_gem/article.rb', line 4 def intro @intro end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
3 4 5 |
# File 'lib/bbc_news_cli_gem/article.rb', line 3 def link @link end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/bbc_news_cli_gem/article.rb', line 3 def title @title end |
#web_page ⇒ Object (readonly)
Returns the value of attribute web_page.
3 4 5 |
# File 'lib/bbc_news_cli_gem/article.rb', line 3 def web_page @web_page end |
Instance Method Details
#add_to_web_page(web_page) ⇒ Object
22 23 24 25 |
# File 'lib/bbc_news_cli_gem/article.rb', line 22 def add_to_web_page(web_page) web_page.articles << self @web_page = web_page end |
#display ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/bbc_news_cli_gem/article.rb', line 27 def display intro ? intro : get_intro puts "*****************************************************************" puts "TITLE: #{title}" puts "-----------------------------------------------------------------" puts "INTRO: #{intro}" puts "*****************************************************************" end |
#open ⇒ Object
36 37 38 |
# File 'lib/bbc_news_cli_gem/article.rb', line 36 def open Launchy.open("#{BbcNewsCliGem::RootAddress + self.link}") end |
#uniq_title ⇒ Object
14 15 16 |
# File 'lib/bbc_news_cli_gem/article.rb', line 14 def uniq_title !web_page.articles.find { | article | article.title == title } end |
#valid_title_and_link ⇒ Object
18 19 20 |
# File 'lib/bbc_news_cli_gem/article.rb', line 18 def valid_title_and_link title && title != "" && link && link != "" && uniq_title end |