Class: NprCliNewsReader::Article

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(article_attributes) ⇒ Article

Returns a new instance of Article.



7
8
9
10
# File 'lib/npr_cli_news_reader/article.rb', line 7

def initialize(article_attributes)
  article_attributes.each { |k, v| self.send("#{k}=", v.strip) }
  @@all << self
end

Instance Attribute Details

#article_urlObject

Returns the value of attribute article_url.



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

def article_url
  @article_url
end

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#full_articleObject

Returns the value of attribute full_article.



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

def full_article
  @full_article
end

#teaserObject

Returns the value of attribute teaser.



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

def teaser
  @teaser
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.allObject



12
13
14
# File 'lib/npr_cli_news_reader/article.rb', line 12

def self.all 
  @@all
end

.sort_articles_by_category(filter) ⇒ Object



20
21
22
# File 'lib/npr_cli_news_reader/article.rb', line 20

def self.sort_articles_by_category(filter)
  self.all.select {|article| article.category == filter.downcase}
end

Instance Method Details

#add_full_article(full_article) ⇒ Object



16
17
18
# File 'lib/npr_cli_news_reader/article.rb', line 16

def add_full_article(full_article)
  self.full_article = full_article
end