Class: Article
- Inherits:
-
Object
- Object
- Article
- Defined in:
- lib/swole-news/article.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#read_time ⇒ Object
Returns the value of attribute read_time.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#workouts ⇒ Object
Returns the value of attribute workouts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(article_hash) ⇒ Article
constructor
A new instance of Article.
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
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/swole-news/article.rb', line 2 def description @description end |
#read_time ⇒ Object
Returns the value of attribute read_time.
2 3 4 |
# File 'lib/swole-news/article.rb', line 2 def read_time @read_time end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/swole-news/article.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/swole-news/article.rb', line 2 def url @url end |
#workouts ⇒ Object
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_workouts ⇒ Object
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 |
.all ⇒ Object
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 |