top_100 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87b1ee07ced999d8c4d5b635e5c8123a575501b0
4
+ data.tar.gz: 91ca23278966a31af426e2c090471f3e9fba5cf7
5
+ SHA512:
6
+ metadata.gz: eba5273f7f5369219bdd4b009ddd861b76001fa229f7d256439114dab0ea516dd1b860362ad38cc15280dc2051b0acd8333be68546e15c478e2b2e42c711b4ce
7
+ data.tar.gz: f58471e9ad5f30fb3aefc58546f6d21b7f5ef5387a09af8174face6b7cee0d2f0ab4ed0c8b096e8ed7ce37a28f9fe551270e0408558b2c213fc373bed2cac54c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in top_100.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Top100
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. Information is acquired through the use of the Nokogiri gem and OpenUri in order to data scrape information from the Billboard website.
4
+
5
+ ## Installation
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:
18
+
19
+ $ gem install top_100
20
+
21
+ ## Usage
22
+
23
+ Enter the requested input in the CLI in order to acquire more information about artists or browse the Billboard charts.
24
+
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
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/top_100.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top_100"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/top_100 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top_100"
5
+
6
+ Top100::CLI.new.call
data/exe/top_100 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top_100"
5
+
6
+ Top100::CLI.new.call
@@ -0,0 +1,32 @@
1
+ class Top100::Artist
2
+ attr_accessor :songs, :name, :location, :date, :bio
3
+ CURRENT_HITS = Top100::BillboardScraper.new.scrape_from_chart_page
4
+
5
+ def initialize(artist_hash)
6
+ artist_hash.each {|key, value| self.send("#{key}=", value)}
7
+ @songs = []
8
+ self.add_current_hits
9
+ end
10
+
11
+ def add_current_hits
12
+ CURRENT_HITS.each { |hit| self.songs << hit[:song_name] if hit[:song_artist].include?(self.name) }
13
+ end
14
+
15
+ def display_details
16
+ puts "Name: #{self.name}"
17
+ puts "From: #{self.location}"
18
+ puts "Formed: #{self.date} "
19
+ puts "Currently Trending Songs: #{self.songs.join(", ")}"
20
+ puts "Bio: #{self.bio}"
21
+ end
22
+
23
+ def self.create_artist(rank)
24
+ info_hash = CURRENT_HITS.find { |hit| hit[:current_rank] == rank }
25
+ unless info_hash == nil
26
+ artist_hash = Top100::BillboardScraper.new.scrape_from_artist_bio_page(info_hash[:artist_bio_link])
27
+ artist = self.new(artist_hash)
28
+ artist
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,33 @@
1
+ class Top100::BillboardScraper
2
+
3
+ def scrape_from_chart_page
4
+ html = open('http://www.billboard.com/charts/hot-100')
5
+ nokogiri_object = Nokogiri::HTML(html)
6
+ charts_array = Array.new
7
+ nokogiri_object.css('div.chart-row__primary').each do |song|
8
+ charts_array << {
9
+ current_rank: song.css('span.chart-row__current-week').text,
10
+ last_week_rank: song.css('span.chart-row__last-week').text,
11
+ song_name: song.css('h2.chart-row__song').text,
12
+ song_artist: song.css('a.chart-row__link').text.strip,
13
+ artist_bio_link: song.css('a.chart-row__link').attribute('href').value + '/biography'
14
+ }
15
+ end
16
+ charts_array
17
+ end
18
+
19
+
20
+ def scrape_from_artist_bio_page(url)
21
+ html = open(url)
22
+ bio = Nokogiri::HTML(html)
23
+ artist = {
24
+ name: bio.css('h1.title').text,
25
+ location: bio.css('dl.facts > dd').text.split(" ")[0].strip,
26
+ date: bio.css('dl.facts > dd').text.match(/\d+/)[0],
27
+ }
28
+ bio.css('aside.bio_sidebar').remove
29
+ artist[:bio] = bio.css('article.bio_content').text.strip
30
+ artist
31
+ end
32
+
33
+ end
@@ -0,0 +1,59 @@
1
+ class Top100::CLI
2
+ attr_accessor :tracker, :current_hits, :scraper
3
+
4
+
5
+ def initialize
6
+ @tracker = 0
7
+ @scraper = Top100::BillboardScraper.new
8
+ @current_hits = self.scraper.scrape_from_chart_page
9
+ end
10
+
11
+
12
+ def call
13
+ puts "Welcome to the Billboard Hot 100. Now outputting the top twenty songs..."
14
+ display_chart
15
+ present_options
16
+ end
17
+
18
+ def display_chart
19
+ if self.tracker >= 100
20
+ puts "There are no more songs to display."
21
+ else
22
+ 20.times do
23
+ hit = self.current_hits[self.tracker]
24
+ puts "##{hit[:current_rank]}: #{hit[:song_name]} by #{hit[:song_artist]}. Previously number #{hit[:last_week_rank]} last week."
25
+ puts "--------------------------------"
26
+ self.tracker += 1
27
+ end
28
+ end
29
+ end
30
+
31
+ def display_artist(rank)
32
+ artist = Top100::Artist.create_artist(rank)
33
+ if artist == nil
34
+ puts "Invalid input"
35
+ else
36
+ artist.display_details
37
+ end
38
+ puts "--------------------------------"
39
+ end
40
+
41
+ def present_options
42
+ puts "Options: 1. type in 'exit' to exit. 2. type in 'next' for the next twenty songs. 3. type in the number of a song for an artist you would like to learn more about."
43
+ choice = gets.chomp
44
+ if choice == 'exit'
45
+ puts "Now exiting..."
46
+ elsif choice == 'next'
47
+ display_chart
48
+ present_options
49
+ elsif choice.match(/\d+/)
50
+ display_artist(choice.match(/\d+/)[0])
51
+ present_options
52
+ else
53
+ puts "Unknown command. Try again."
54
+ present_options
55
+ end
56
+ end
57
+
58
+
59
+ end
@@ -0,0 +1,3 @@
1
+ module Top100
2
+ VERSION = "0.3.0"
3
+ end
data/lib/top_100.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ require_relative "./top_100/version.rb"
5
+ require_relative "./top_100/billboard_scraper.rb"
6
+ require_relative "./top_100/artist.rb"
7
+ require_relative "./top_100/cli.rb"
data/top_100.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'top_100/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "top_100"
8
+ spec.version = Top100::VERSION
9
+ spec.authors = ["viparthasarathy"]
10
+ spec.email = ["viparthasarathy@gmail.com"]
11
+ spec.summary = %q{A CLI gem that allows the user to acquire information about trending songs and artists.}
12
+ spec.homepage = "https://github.com/viparthasarathy/top-100"
13
+ spec.executables = ["top_100"]
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.require_paths = ["lib", "lib/top_100"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "nokogiri"
24
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top_100
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - viparthasarathy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - viparthasarathy@gmail.com
72
+ executables:
73
+ - top_100
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - bin/top_100
86
+ - exe/top_100
87
+ - lib/top_100.rb
88
+ - lib/top_100/artist.rb
89
+ - lib/top_100/billboard_scraper.rb
90
+ - lib/top_100/cli.rb
91
+ - lib/top_100/version.rb
92
+ - top_100.gemspec
93
+ homepage: https://github.com/viparthasarathy/top-100
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ - lib/top_100
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A CLI gem that allows the user to acquire information about trending songs
117
+ and artists.
118
+ test_files: []