Class: BbcNewsCliGem::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/bbc_news_cli_gem/article.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#introObject

Returns the value of attribute intro.



4
5
6
# File 'lib/bbc_news_cli_gem/article.rb', line 4

def intro
  @intro
end

Returns the value of attribute link.



3
4
5
# File 'lib/bbc_news_cli_gem/article.rb', line 3

def link
  @link
end

#titleObject (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_pageObject (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

#displayObject



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

#openObject



36
37
38
# File 'lib/bbc_news_cli_gem/article.rb', line 36

def open
  Launchy.open("#{BbcNewsCliGem::RootAddress + self.link}")
end

#uniq_titleObject



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


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