top_100 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e21dac25608831639b77949e53ffafb7c0c4c252
4
- data.tar.gz: b13d90db57f2109b578276d1cb4163efb5ea23e1
3
+ metadata.gz: 80b7a337d41c32d15679fbb43e063b7153c01dd2
4
+ data.tar.gz: 92bef06913a8b7e7476d25730f2c9741afe9b416
5
5
  SHA512:
6
- metadata.gz: de7abbd93ef1cd9fc8b3dc80b8f48a080618d4e6302f1c3b8c177106a4b27c4f8f9e19c13d2faa7e6ecab7b03f45b9b96ab4618f783edc0094676b36aefc2993
7
- data.tar.gz: aab81a239aab2d9497085dd6bea3cb4cf8501b2c9fa7a6afabd627b0b6d28383b513031cbb409b6ce58fbab9b7dea909a22f74529817fd753af334b12c05f92d
6
+ metadata.gz: 6de66ededf599ac13c1adff49bf8f52bd4ca3196b8c7538e913166356b80f3f745219fe885b50aea75e7751d4dc97d5c938af38df5ee05555879d4afb59fc143
7
+ data.tar.gz: ece663afd0399b4bec751db111e6b3b4676375dbcad91294c79c71d8d42a9d8671624e6a45e09898b214865f6e9c7855efc73b0f8a5fb29b6a072c244a6948a0
data/README.md CHANGED
@@ -1,20 +1,10 @@
1
1
  # Top100
2
2
 
3
- This gem allows the user to interact with the Billboard's Top 100 via the command line interface. Users can acquire a real time list of trending songs and acquire more information about the artists responsible for the works. Users can also open up Spotify links in their default browser of any songs they wish to hear. Information is acquired through the use of the Nokogiri gem and OpenUri in order to scrape data and information from the Billboard website.
3
+ This gem allows the user to interact with the Billboard's Top 100 via the command line interface. Users can acquire a real time list of trending songs and acquire more information about the artists responsible for the works. Users can also open up Spotify links in their default browser of any songs they wish to hear. Information is acquired through multiple sources, including RSS feeds, the Spotify API, and the Nokogiri gem and OpenUri for data scraping purposes.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'top_100', :git => 'https://github.com/viparthasarathy/top-100.git'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
7
+ Type the following command in terminal:
18
8
 
19
9
  $ gem install top_100
20
10
 
@@ -22,11 +12,6 @@ Or install it yourself as:
22
12
 
23
13
  After installation, execute the gem by inputting top_100 into the console. The user will now be able to interact with the gem and request more information about the Billboard Top 100 or read the biographical information about trending artists.
24
14
 
25
- ## Development
26
-
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
-
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
15
 
31
16
  ## Contributing
32
17
 
data/bin/top_100 CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "top_100"
3
+ # require "bundler/setup"
4
+ require_relative "../lib/top_100"
5
5
 
6
6
  CLI.new.call
@@ -13,20 +13,12 @@ class Artist
13
13
  end
14
14
  end
15
15
 
16
- def display_details
17
- puts "Name: #{self.name}"
18
- puts "From: #{self.location}"
19
- puts "Formed: #{self.date} "
20
- song_names = self.songs.map {|song| song.name}
21
- puts "Currently Trending Songs: #{song_names.join(", ")}"
22
- puts "Bio: #{self.bio}"
23
- end
24
-
25
16
  def self.all
26
17
  @@artists
27
18
  end
28
19
 
29
20
  #Artists have unique names, search for a match using the name or create a new Artist object.
21
+ # ISSUE: song.artist_name and Artist.name will not match if the song has collaborators, meaning that a new artist object will be created each time.
30
22
  def self.find_or_create(artist_name)
31
23
  Artist.all.each {|artist| return artist if artist.name == artist_name}
32
24
  Artist.new(artist_name)
@@ -11,7 +11,10 @@ class BillboardScraper
11
11
  song_hash = {
12
12
  rank: rank,
13
13
  name: name,
14
- #feed doesn't seem to offer an artist value, requiring us to extract artist name from description instead.
14
+ #ISSUE: RSS Parser feed doesn't seem to offer an artist value, requiring us to extract artist name from description instead. Alternatively, Nokogiri::XML can also open up the RSS information.
15
+ # Regardless, the HTML page has to be opened for the artist_url information, and as a result, the gem is suspectible to breaking due to front-end design changes.
16
+ #ISSUE: Collaborators saved as part of the artist name, which causes some difficulties with the search term for looking up the artist biography.
17
+ # One possible solution would be to compare artist_name and the artist_url slug value in order to determine where the artist name begins and ends and then save that value to song instead.
15
18
  artist_name: song.description.split("#{name} by ")[1].split(" ranks ##{rank}")[0],
16
19
  artist_url: billboard_page.css('a.chart-row__artist')[index].attribute('href').value + '/biography',
17
20
  }
data/lib/top_100/cli.rb CHANGED
@@ -13,23 +13,6 @@ class CLI
13
13
  present_options
14
14
  end
15
15
 
16
- def display_chart
17
- if self.tracker >= 100
18
- puts "There are no more songs to display."
19
- else
20
- 20.times do
21
- Song.all[self.tracker].display
22
- self.tracker += 1
23
- end
24
- end
25
- end
26
-
27
- def display_artist(name)
28
- artist = Artist.find_or_create(name)
29
- artist.name == nil ? puts("Artist not found.") : artist.display_details
30
- puts "--------------------------------"
31
- end
32
-
33
16
  def present_options
34
17
  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
18
  choice = gets.chomp
@@ -42,7 +25,7 @@ class CLI
42
25
  when 'song'
43
26
  puts "Enter the chart number of the song you would like to play."
44
27
  rank = gets.chomp
45
- Song.play(rank)
28
+ play_song(Song.find_by_rank(rank))
46
29
  present_options
47
30
  else
48
31
  begin
@@ -55,4 +38,50 @@ class CLI
55
38
  end
56
39
  end
57
40
 
41
+ def play_song(song)
42
+ if song.nil?
43
+ puts "You've entered an invalid chart rank."
44
+ else
45
+ song.url = song.spotify_link
46
+ #check if song has a valid url, copyright issues with certain songs
47
+ if !!song.url
48
+ puts "Playing song..."
49
+ `open #{song.url}`
50
+ else
51
+ puts "Sorry, that artist does not have their song on Spotify."
52
+ end
53
+ end
54
+ end
55
+
56
+ def display_chart
57
+ if self.tracker >= 100
58
+ puts "There are no more songs to display."
59
+ else
60
+ 20.times do
61
+ display_song(Song.all[self.tracker])
62
+ self.tracker += 1
63
+ end
64
+ end
65
+ end
66
+
67
+ def display_artist(name)
68
+ artist = Artist.find_or_create(name)
69
+ if artist.name == nil
70
+ puts "Artist not found."
71
+ else
72
+ song_names = artist.songs.map {|song| song.name}
73
+ puts "Name: #{artist.name}"
74
+ puts "From: #{artist.location}"
75
+ puts "Formed: #{artist.date} "
76
+ puts "Currently Trending Songs: #{song_names.join(", ")}"
77
+ puts "Bio: #{artist.bio}"
78
+ end
79
+ puts "--------------------------------"
80
+ end
81
+
82
+ def display_song(song)
83
+ puts "##{song.rank}: #{song.name} by #{song.artist_name}."
84
+ puts "--------------------------------"
85
+ end
86
+
58
87
  end
data/lib/top_100/song.rb CHANGED
@@ -7,20 +7,15 @@ class Song
7
7
  @@songs << self
8
8
  end
9
9
 
10
- def display
11
- puts "##{self.rank}: #{self.name} by #{self.artist_name}."
12
- puts "--------------------------------"
13
- end
14
-
15
10
  #slug method used to help make query for spotify API request
16
11
  def slug
17
12
  self.name.gsub(/\s+/, "%20").delete('^a-zA-Z0-9\%').downcase
18
13
  end
19
14
 
20
-
21
15
  def spotify_link
22
16
  response = open("https://api.spotify.com/v1/search?q=#{self.slug}&type=track").read
23
17
  json_info = JSON.parse(response)
18
+ # songs share same track name, ensure that artist name includes the first artist to find a match.
24
19
  song_details = json_info["tracks"]["items"].find { |info| self.artist_name.downcase.include?(info["artists"][0]["name"].downcase) }
25
20
  song_details == nil ? nil : song_details["preview_url"]
26
21
  end
@@ -31,20 +26,8 @@ class Song
31
26
  @@songs
32
27
  end
33
28
 
34
- def self.play(rank)
29
+ def self.find_by_rank(rank)
35
30
  song = Song.all.find {|song| song.rank == rank }
36
- if song.nil?
37
- puts "You've entered an invalid chart name."
38
- else
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
47
- end
48
31
  end
49
32
 
50
33
  end
@@ -1,3 +1,3 @@
1
1
  module Top100
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.2"
3
3
  end
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: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - viparthasarathy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler