top_100 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/top_100/artist.rb +2 -2
- data/lib/top_100/billboard_scraper.rb +3 -3
- data/lib/top_100/cli.rb +1 -1
- data/lib/top_100/song.rb +21 -6
- data/lib/top_100/version.rb +1 -1
- data/lib/top_100.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cdc6f615b54a430d8c734a1c3613b0e09489b7e
|
4
|
+
data.tar.gz: fb4f3c3c601ba5739a01252f5e2e7ebe24b4814f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d01ed501358d0be5a3dd7c37b279c8a4348b5d0e4dc1d568af31a4bd46ad781bf53d150a18171141bc314c0eba679ab5f93fc05c8d3c637a090cf50799c021
|
7
|
+
data.tar.gz: b5b28d3fd233c9fb0a094ed8e7e92e096f8b19e7eb4d5e651980dfea07a4acc83412d65d29000fc174f99f420a8bc4cb5c28ecba039ceb620e302d82fd8f462b
|
data/.gitignore
CHANGED
data/lib/top_100/artist.rb
CHANGED
@@ -17,7 +17,7 @@ class Artist
|
|
17
17
|
puts "Name: #{self.name}"
|
18
18
|
puts "From: #{self.location}"
|
19
19
|
puts "Formed: #{self.date} "
|
20
|
-
song_names = self.songs.map {|
|
20
|
+
song_names = self.songs.map {|song| song.name}
|
21
21
|
puts "Currently Trending Songs: #{song_names.join(", ")}"
|
22
22
|
puts "Bio: #{self.bio}"
|
23
23
|
end
|
@@ -28,7 +28,7 @@ class Artist
|
|
28
28
|
|
29
29
|
#Artists have unique names, search for a match using the name or create a new Artist object.
|
30
30
|
def self.find_or_create(artist_name)
|
31
|
-
Artist.all.each {|
|
31
|
+
Artist.all.each {|artist| return artist if artist.name == artist_name}
|
32
32
|
Artist.new(artist_name)
|
33
33
|
end
|
34
34
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
class BillboardScraper
|
2
2
|
|
3
|
+
|
4
|
+
# will only use class methods, no need to create instances as there's nothing unique between these scrapers and we only need one.
|
5
|
+
|
3
6
|
def self.scrape_from_chart_page
|
4
7
|
nokogiri_object = Nokogiri::HTML(open('http://www.billboard.com/charts/hot-100'))
|
5
8
|
nokogiri_object.css('div.chart-row__primary').each do |song|
|
6
|
-
url = song.css('a.chart-row__player-link')
|
7
9
|
name = song.css('h3.chart-row__artist').text.strip.split(//)
|
8
10
|
song_hash = {
|
9
11
|
rank: song.css('span.chart-row__current-week').text,
|
10
12
|
name: song.css('h2.chart-row__song').text,
|
11
13
|
artist_bio_url: song.css('a.chart-row__link').attribute('href').value + '/biography',
|
12
14
|
artist_name: song.css('h3.chart-row__artist').text.strip,
|
13
|
-
# missing url for some songs due to copyright issues, save url as nil for such songs
|
14
|
-
url: url.empty? ? nil : url.attribute('href').value
|
15
15
|
}
|
16
16
|
Song.new(song_hash)
|
17
17
|
end
|
data/lib/top_100/cli.rb
CHANGED
@@ -31,7 +31,7 @@ class CLI
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def present_options
|
34
|
-
puts "Options: 1. type in 'exit' to exit. 2. type in 'next' for the next twenty songs. 3. type 'song' to
|
34
|
+
puts "Options: 1. type in 'exit' to exit. 2. type in 'next' for the next twenty songs. 3. type 'song' to play a song sample. 4. type in the full artist title of a song to learn more about the main artist."
|
35
35
|
choice = gets.chomp
|
36
36
|
case choice
|
37
37
|
when 'exit'
|
data/lib/top_100/song.rb
CHANGED
@@ -7,18 +7,33 @@ class Song
|
|
7
7
|
@@songs << self
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.all
|
11
|
-
@@songs
|
12
|
-
end
|
13
|
-
|
14
10
|
def display
|
15
11
|
puts "##{self.rank}: #{self.name} by #{self.artist_name}."
|
16
12
|
puts "--------------------------------"
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
#slug method used to help make query for spotify API request
|
16
|
+
def slug
|
17
|
+
self.name.gsub(/\s+/, "%20").delete('^a-zA-Z0-9\-').downcase
|
18
|
+
end
|
21
19
|
|
20
|
+
|
21
|
+
def spotify_link
|
22
|
+
response = open("https://api.spotify.com/v1/search?q=#{self.slug}&type=track").read
|
23
|
+
json_info = JSON.parse(response)
|
24
|
+
song_details = json_info["tracks"]["items"].find { |info| self.artist_name.downcase.include?(info["artists"][0]["name"].downcase) }
|
25
|
+
song_details == nil ? nil : song_details["preview_url"]
|
26
|
+
end
|
27
|
+
|
28
|
+
# class methods
|
29
|
+
|
30
|
+
def self.all
|
31
|
+
@@songs
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.play(rank)
|
35
|
+
song = Song.all.find {|song| song.rank == rank }
|
36
|
+
song.url = song.spotify_link
|
22
37
|
if song.nil?
|
23
38
|
puts "You've entered an invalid chart name."
|
24
39
|
#check if song has a valid url, copyright issues with certain songs
|
data/lib/top_100/version.rb
CHANGED
data/lib/top_100.rb
CHANGED
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.
|
4
|
+
version: 2.1.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-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|