Class: NewsReader::Article

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/news_reader/article.rb', line 2

def date
  @date
end

#textObject

Returns the value of attribute text.



2
3
4
# File 'lib/news_reader/article.rb', line 2

def text
  @text
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/news_reader/article.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/news_reader/article.rb', line 2

def url
  @url
end

Class Method Details

.allObject



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

.listObject



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


53
54
55
56
# File 'lib/news_reader/article.rb', line 53

def self.menu
    puts "Please choose an article from 1 to #{self.all.size} to read"
    puts "Type `menu` to go to the main menu"
end

.readObject



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.menu
    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.menu
        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