Class: APWArticles::Article

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#authorObject

Returns the value of attribute author.



2
3
4
# File 'lib/apw_articles/article.rb', line 2

def author
  @author
end

#blurbObject

Returns the value of attribute blurb.



2
3
4
# File 'lib/apw_articles/article.rb', line 2

def blurb
  @blurb
end

#categoriesObject

Returns the value of attribute categories.



2
3
4
# File 'lib/apw_articles/article.rb', line 2

def categories
  @categories
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/apw_articles/article.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/apw_articles/article.rb', line 2

def url
  @url
end

Class Method Details

.allObject



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