Class: Article

Inherits:
Object
  • Object
show all
Defined in:
lib/swole-news/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.



6
7
8
9
# File 'lib/swole-news/article.rb', line 6

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

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/swole-news/article.rb', line 2

def description
  @description
end

#read_timeObject

Returns the value of attribute read_time.



2
3
4
# File 'lib/swole-news/article.rb', line 2

def read_time
  @read_time
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/swole-news/article.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/swole-news/article.rb', line 2

def url
  @url
end

#workoutsObject

Returns the value of attribute workouts.



2
3
4
# File 'lib/swole-news/article.rb', line 2

def workouts
  @workouts
end

Class Method Details

.add_workoutsObject



16
17
18
19
20
21
22
# File 'lib/swole-news/article.rb', line 16

def self.add_workouts
  @@all.map do |article|
    scraped_workouts = Scraper.scrape_workouts(article.url)
    article.workouts = Workout.create_from_collection(scraped_workouts)
    article.workouts.each {|workout| workout.article = article}
  end
end

.allObject



24
25
26
# File 'lib/swole-news/article.rb', line 24

def self.all
  @@all
end

.create_from_collection(article_array) ⇒ Object



11
12
13
14
# File 'lib/swole-news/article.rb', line 11

def self.create_from_collection(article_array)
  article_array.map{|article_hash|self.new(article_hash)}
  self.add_workouts
end