Class: PitchforkReviews::Album

Inherits:
Object
  • Object
show all
Defined in:
lib/pitchfork_reviews/album.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def artist
  @artist
end

#best_new_albumObject

Returns the value of attribute best_new_album.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def best_new_album
  @best_new_album
end

#genreObject

Returns the value of attribute genre.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def genre
  @genre
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def name
  @name
end

#scoreObject

Returns the value of attribute score.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def score
  @score
end

#summaryObject

Returns the value of attribute summary.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/pitchfork_reviews/album.rb', line 2

def url
  @url
end

Class Method Details

.scrape_pitchforkObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pitchfork_reviews/album.rb', line 4

def self.scrape_pitchfork
  albums = []
  doc = Nokogiri::HTML(open("http://pitchfork.com/reviews/albums/"))
  doc.css(".review").each do |review|
    all_genres = []
    all_artists = []
    all_scores = []
    album = self.new
    album.name = review.css(".title").text
    
    review.css("div.album-artist ul li").each do |a|
      all_artists << a.text
      end
    album.artist = all_artists.to_s.gsub('"', "").gsub('[', "").gsub("]", "")
    
    review.css("ul.genre-list.before.inline li").each do |g|
      all_genres << g.text
      end
    album.genre = all_genres.to_s.gsub('"', "").gsub('[', "").gsub("]", "")
    
    album.url = review.css(".album-link")[0]["href"]
      if review.text.include?("Best New Album")
        album.best_new_album = " ** Best New Album **"
      end
    page = Nokogiri::HTML(open("http://pitchfork.com#{album.url}"))
    
    album.score = page.css(".score-circle").text[0..2]
    album.summary = page.css("div.abstract").text.gsub("Â" , "").gsub("â" , "'")
  albums << album
  end
  albums
end