top_100 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48ca9ee2f35c7db065e9293b2b0c4bde84665a5c
4
- data.tar.gz: a35e02a87a2b7270e64afe78dba11861da9f3b49
3
+ metadata.gz: 5fe32f7a0fab14ff549576f8d75ff1c06c8e0a83
4
+ data.tar.gz: ec46bebc741cb4276bbede3ff8bb9e48ebdb72d5
5
5
  SHA512:
6
- metadata.gz: 0a91f26ddf7c9cbe4e820e543c59da0c1fd8d909f2d2c7caa3df6bd2afd1b3afd9dd5e2b4f4341a9f8dddeae51b94025ce076bc6da659420c7b2bce668ade2ca
7
- data.tar.gz: da1fcabcdb1dbd68b8e3c49511af171455e366f430984d9a41487740ee8d29416948c34ad36bdc0912772c9015d082cbd93946c13d4f8ab39bc8c60158727227
6
+ metadata.gz: 13c94798d79400eba455a74c85f55153c0e5dfa63d1ef58ed8adeff494b17c7f359f8a6cbc461ae20ccf8c0e9821a7c77648b0de2b4f37c42d6a5c431cbb07d2
7
+ data.tar.gz: ec2ee9e2c5a2cd7bf452d028630dad6c1a5091c0c63cc6c93785257626de9535701c0c3ab0e6a27510cc30582f73980f62dcff0faf573d8e32c221c71e4fa576
@@ -8,7 +8,7 @@ class Artist
8
8
  if @songs.empty?
9
9
  self.name = nil
10
10
  else
11
- BillboardScraper.scrape_from_artist_bio_page(@songs[0].artist_bio_url).each {|key, value| self.send("#{key}=", value)}
11
+ BillboardScraper.scrape_from_artist_bio_page(@songs[0].artist_url).each {|key, value| self.send("#{key}=", value)}
12
12
  @@artists << self
13
13
  end
14
14
  end
@@ -1,17 +1,19 @@
1
1
  class BillboardScraper
2
2
 
3
-
4
3
  # will only use class methods, no need to create instances as there's nothing unique between these scrapers and we only need one.
5
-
6
4
  def self.scrape_from_chart_page
7
- nokogiri_object = Nokogiri::HTML(open('http://www.billboard.com/charts/hot-100'))
8
- nokogiri_object.css('div.chart-row__primary').each do |song|
9
- name = song.css('h3.chart-row__artist').text.strip.split(//)
5
+ billboard_page = Nokogiri::HTML(open('http://www.billboard.com/charts/hot-100'))
6
+ rss = RSS::Parser.parse(open('http://www.billboard.com/rss/charts/hot-100'))
7
+ rss.items.each_with_index do |song, index|
8
+ #account for any song titles that might happen to have ': ' in their title.
9
+ name = song.title.split(": ")[1..-1].join(": ")
10
+ rank = song.title.split(": ")[0]
10
11
  song_hash = {
11
- rank: song.css('span.chart-row__current-week').text,
12
- name: song.css('h2.chart-row__song').text,
13
- artist_bio_url: song.css('a.chart-row__link').attribute('href').value + '/biography',
14
- artist_name: song.css('h3.chart-row__artist').text.strip,
12
+ rank: rank,
13
+ name: name,
14
+ #feed doesn't seem to offer an artist value, requiring us to extract artist name from description instead.
15
+ artist_name: song.description.split("#{name} by ")[1].split(" ranks ##{rank}")[0],
16
+ artist_url: billboard_page.css('h3.chart-row__artist a.chart-row__link')[index].attribute('href').value + '/biography',
15
17
  }
16
18
  Song.new(song_hash)
17
19
  end
data/lib/top_100/song.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Song
2
- attr_accessor :rank, :name, :artist_name, :artist_bio_url, :url
2
+ attr_accessor :rank, :name, :artist_name, :artist_url, :url
3
3
  @@songs = []
4
4
 
5
5
  def initialize(song_hash)
@@ -33,15 +33,17 @@ class Song
33
33
 
34
34
  def self.play(rank)
35
35
  song = Song.all.find {|song| song.rank == rank }
36
- song.url = song.spotify_link
37
36
  if song.nil?
38
37
  puts "You've entered an invalid chart name."
39
- #check if song has a valid url, copyright issues with certain songs
40
- elsif !!song.url
41
- puts "Playing song..."
42
- `open #{song.url}`
43
38
  else
44
- puts "Sorry, that artist does not have their song on Spotify."
39
+ song.url = song.spotify_link
40
+ #check if song has a valid url, copyright issues with certain songs
41
+ if !!song.url
42
+ puts "Playing song..."
43
+ `open #{song.url}`
44
+ else
45
+ puts "Sorry, that artist does not have their song on Spotify."
46
+ end
45
47
  end
46
48
  end
47
49
 
@@ -1,3 +1,3 @@
1
1
  module Top100
2
- VERSION = "2.1.1"
2
+ VERSION = "3.0.0"
3
3
  end
data/lib/top_100.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'open-uri'
1
+ require 'rss'
2
2
  require 'nokogiri'
3
3
  require 'json'
4
4
 
5
+
5
6
  require_relative "./top_100/version.rb"
6
7
  require_relative "./top_100/billboard_scraper.rb"
7
8
  require_relative "./top_100/artist.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top_100
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - viparthasarathy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler