Class: Article

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(article_hash) ⇒ Article

Returns a new instance of Article.



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

def initialize(article_hash)
  article_hash.each {|key, value| self.send(("#{key}="), value)}
  @@all << self
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all
  @@all
end

.create_from_collection(articles_array) ⇒ Object



13
14
15
16
17
# File 'lib/article.rb', line 13

def self.create_from_collection(articles_array)
  articles_array.each do |article_hash|
    Article.new(article_hash)
  end
end

.resetObject



23
24
25
# File 'lib/article.rb', line 23

def self.reset
  @all.clear
end