Class: APWArticles::Article
- Inherits:
-
Object
- Object
- APWArticles::Article
- Defined in:
- lib/apw_articles/article.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#blurb ⇒ Object
Returns the value of attribute blurb.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attribute_hash) ⇒ Article
constructor
A new instance of Article.
Constructor Details
#initialize(attribute_hash) ⇒ Article
Returns a new instance of Article.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/apw_articles/article.rb', line 5 def initialize(attribute_hash) self.categories = [] attribute_hash.each do |key, value| if key == :categories value.each do |category| c = APWArticles::Category.find_or_create_by_url(category) self.categories << c c.articles << self end else self.send(("#{key}="), value) end @@all << self end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
2 3 4 |
# File 'lib/apw_articles/article.rb', line 2 def end |
#blurb ⇒ Object
Returns the value of attribute blurb.
2 3 4 |
# File 'lib/apw_articles/article.rb', line 2 def blurb @blurb end |
#categories ⇒ Object
Returns the value of attribute categories.
2 3 4 |
# File 'lib/apw_articles/article.rb', line 2 def categories @categories end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/apw_articles/article.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/apw_articles/article.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
29 30 31 |
# File 'lib/apw_articles/article.rb', line 29 def self.all @@all end |
.new_from_list(list_url) ⇒ Object
25 26 27 |
# File 'lib/apw_articles/article.rb', line 25 def self.new_from_list(list_url) # call scraper for list and then initalize from hash end |
.new_from_url(url) ⇒ Object
21 22 23 |
# File 'lib/apw_articles/article.rb', line 21 def self.new_from_url(url) self.new(APWArticles::Scraper.scrape_article(url)) end |