Class: NewsReader::Article
- Inherits:
-
Object
- Object
- NewsReader::Article
- Defined in:
- lib/news_reader/article.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#text ⇒ Object
Returns the value of attribute text.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_attributes(attributes) ⇒ Object
-
#initialize(article) ⇒ Article
constructor
A new instance of Article.
Constructor Details
#initialize(article) ⇒ Article
Returns a new instance of Article.
5 6 7 8 9 10 |
# File 'lib/news_reader/article.rb', line 5 def initialize article article.each do |key, value| self.send("#{key}=", value) end @@all << self end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/news_reader/article.rb', line 2 def date @date end |
#text ⇒ Object
Returns the value of attribute text.
2 3 4 |
# File 'lib/news_reader/article.rb', line 2 def text @text end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/news_reader/article.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/news_reader/article.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
57 58 59 |
# File 'lib/news_reader/article.rb', line 57 def self.all @@all end |
.import(collection) ⇒ Object
18 19 20 21 22 |
# File 'lib/news_reader/article.rb', line 18 def self.import collection collection.each do |article| NewsReader::Article.new article end end |
.list ⇒ Object
24 25 26 27 28 29 |
# File 'lib/news_reader/article.rb', line 24 def self.list puts "--------- Blog Articles ---------" @@all.each.with_index(1) do |article, index| puts " - #{index}. #{article.title}" end end |
.menu ⇒ Object
53 54 55 56 |
# File 'lib/news_reader/article.rb', line 53 def self. puts "Please choose an article from 1 to #{self.all.size} to read" puts "Type `menu` to go to the main menu" end |
.read ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/news_reader/article.rb', line 31 def self.read self.list self. input = nil while input != "menu" input = gets.strip index = input.to_i - 1 if !index.between?(0, self.all.size - 1) puts "(-_-) You must choose an article that exists in our database" else article = self.all[index] puts "------ #{article.title} ------" puts "-- Date Published: #{article.date}" puts "-- Article Text: #{article.text}" puts "-- Ctr/Alt + click http://www.loremipsum.biz/blog#{article.url} to go to the article page." puts "------ ------ ------ ------ ------" self. end end end |
Instance Method Details
#add_attributes(attributes) ⇒ Object
12 13 14 15 16 |
# File 'lib/news_reader/article.rb', line 12 def add_attributes attributes attributes.each do |key, value| self.send("#{key}=", value) end end |