billboard-top-100 1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/billboard-top-100.rb +36 -0
  3. data/lib/track.rb +12 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77c0383099b18c58a6211032ed94060204c1e489
4
+ data.tar.gz: b5abee0f7f955ebffb2d6be1dc3f3dbef238b013
5
+ SHA512:
6
+ metadata.gz: c3f5456ae1cacdc52beaa81aa62eb30e9b2824613403a3ff599afcdba4cc1fdf65e683802d2e51bd9b8eb38eca47c7ec72aab704379af7fa211254f20e21357b
7
+ data.tar.gz: 2fbd572a6bfa69c2e257fa8a86b40653856c87fbd72e7df8de6afd1d0a3563a5f09d5776090dc552a36e5f1d1bdce8e863f22a0ca3795109122751419839e42e
@@ -0,0 +1,36 @@
1
+ require 'HTTParty'
2
+ require 'Nokogiri'
3
+ require 'track'
4
+
5
+ class BillboardTop100
6
+ def getTop100(date = "")
7
+ url = 'http://www.billboard.com/charts/hot-100'
8
+ if date.length > 0
9
+ url += '/' + date
10
+ end
11
+ tracks = []
12
+ titles = []
13
+ artists = []
14
+ covers = []
15
+ page = HTTParty.get(url)
16
+ parser = Nokogiri::HTML(page)
17
+ parser.css('.chart-row__song').each do |title|
18
+ titles.push(title.text)
19
+ end
20
+ parser.css('.chart-row__artist').each do |artist|
21
+ artists.push(artist.text.to_s.squeeze(" ")[2..artist.to_s.length - 1].gsub("\n", ""))
22
+ end
23
+ parser.css('.chart-row__image').each do |cover|
24
+ if cover.to_s.include? 'background-image'
25
+ covers.push(cover.to_s.split('url(')[1].to_s.split(')')[0])
26
+ else
27
+ covers.push(cover.to_s.split('imagesrc="')[1].to_s.split('">')[0])
28
+ end
29
+ end
30
+ for i in 0..99
31
+ track = Track.new(titles[i], artists[i], i + 1, covers[i])
32
+ tracks[i] = track
33
+ end
34
+ return tracks
35
+ end
36
+ end
data/lib/track.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Track
2
+ attr_accessor :title
3
+ attr_accessor :artist
4
+ attr_accessor :rank
5
+ attr_accessor :cover
6
+ def initialize(title, artist, rank, cover)
7
+ @title = title
8
+ @artist = artist
9
+ @rank = rank
10
+ @cover = cover
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: billboard-top-100
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rishi Masand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Retrieve top 100 songs from Billboard's "The Hot 100"
14
+ email: masandrishi@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/billboard-top-100.rb
20
+ - lib/track.rb
21
+ homepage: http://rubygems.org/gems/billboard-top-100
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.8
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Billboard Hot 100
45
+ test_files: []