Class: Article

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

Overview

> Handles Article object creation

Constant Summary collapse

@@all =

> Set each of our Class arrays to a blank array

[]
@@recents =
[]
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(article_hash) ⇒ Article

> Creates new Article objects



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/crowder_news/article.rb', line 16

def initialize(article_hash)
  @title = article_hash[:title]
  @link = article_hash[:link]
  @excerpt = article_hash[:excerpt]
  @type = article_hash[:type]

  if @type.downcase == "recent"
    @@recents << self
  elsif @type.downcase == "featured"
    @@featured << self
  end
  @@all << self;
end

Instance Attribute Details

#authorObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def author
  @author
end

#bodyObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def body
  @body
end

#dateObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def date
  @date
end

#excerptObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def excerpt
  @excerpt
end

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def link
  @link
end

#titleObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def title
  @title
end

#typeObject

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def type
  @type
end

> Accessors for article details



6
7
8
# File 'lib/crowder_news/article.rb', line 6

def youtube_links
  @youtube_links
end

Class Method Details

.allObject

> Getter returns all of our article objects



50
51
52
# File 'lib/crowder_news/article.rb', line 50

def self.all
  @@all;
end

.create_from_collection(articles_array) ⇒ Object

> Creates articles from a hash of article information



33
34
35
36
37
# File 'lib/crowder_news/article.rb', line 33

def self.create_from_collection(articles_array)
  articles_array.each { |hash|
    self.new(hash)
  }
end

> Getter returns all of our featured articles



60
61
62
# File 'lib/crowder_news/article.rb', line 60

def self.featured
  @@featured
end

.recentsObject

> Getter returns all of our recent articles



55
56
57
# File 'lib/crowder_news/article.rb', line 55

def self.recents
  @@recents
end

Instance Method Details

#add_details(details_hash) ⇒ Object

> Adds the additional details to our Article object



42
43
44
45
46
47
# File 'lib/crowder_news/article.rb', line 42

def add_details(details_hash)
  @author = details_hash[:author]
  @date = details_hash[:date]
  @body = details_hash[:body]
  @youtube_links = details_hash[:youtube_links]
end