billboard_hot_100 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/billboard_hot_100/cli.rb +1 -0
- data/lib/billboard_hot_100/scraper.rb +22 -0
- data/lib/billboard_hot_100/song.rb +12 -26
- data/lib/billboard_hot_100/version.rb +1 -1
- data/spec.md +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08521431a492c0c67e04977c4042b69f9ccce5c5'
|
4
|
+
data.tar.gz: 81c336e3d2eae45e3592385308d6e6604fcb2beb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d4f772778383f825e65b7c99caf4f3f1579868242e02c41816d5848cb023dcff7bd5f732f01430761abb425f3fcad23ba12e0c13b1ce4b53ea0d50c65d2db7
|
7
|
+
data.tar.gz: 695d828da1f143521fc6c1ba65a4b393aa8431774f1fc4fdad68faf534cee3ad4d2ef882f4c2eae1e3b5eea98987b87b86d01af87088626df62ca75d16a1f12f
|
data/README.md
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class BillboardHot100::Scraper
|
2
|
+
# Scrape songs from https://www.billboard.com/charts/hot-100
|
3
|
+
def self.scrape_songs
|
4
|
+
page_html = Nokogiri::HTML(open("https://www.billboard.com/charts/hot-100"))
|
5
|
+
chart = page_html.css(".chart-data .container")
|
6
|
+
|
7
|
+
#Iterate through the first 100 rows of the billboard chart
|
8
|
+
#Create instances of the Song class during each iteration
|
9
|
+
rows = chart.css(".chart-row")
|
10
|
+
rows.each do |row|
|
11
|
+
song = BillboardHot100::Song.new
|
12
|
+
song.title = row.css(".chart-row__song").text
|
13
|
+
song.artist = row.css(".chart-row__artist").text.strip
|
14
|
+
song.current_rank = row.css(".chart-row__current-week").text
|
15
|
+
song.last_week_rank = row.css(".chart-row__secondary .chart-row__last-week .chart-row__value").text
|
16
|
+
song.peak_position = row.css(".chart-row__secondary .chart-row__top-spot .chart-row__value").text
|
17
|
+
song.weeks = row.css(".chart-row__secondary .chart-row__weeks-on-chart .chart-row__value").text
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -1,36 +1,22 @@
|
|
1
1
|
class BillboardHot100::Song
|
2
|
+
# Build a Scraper class that scrapes data and sends it to Song to create new song instances
|
3
|
+
|
2
4
|
# set up attributes for each instance
|
3
5
|
attr_accessor :title, :artist, :current_rank, :last_week_rank, :peak_position, :weeks
|
6
|
+
@@all = []
|
4
7
|
|
5
8
|
# Return this week's Billboard Hot 100 based on scraped data
|
6
|
-
def
|
7
|
-
@@all
|
8
|
-
if range == 1
|
9
|
-
@@all[0, 10]
|
10
|
-
else
|
11
|
-
@@all["#{range-1}0".to_i, 10]
|
12
|
-
end
|
9
|
+
def initialize
|
10
|
+
@@all << self
|
13
11
|
end
|
14
12
|
|
15
|
-
#
|
16
|
-
def self.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
rows = chart.css(".chart-row")
|
23
|
-
songs = []
|
24
|
-
rows.collect do |row|
|
25
|
-
song = self.new
|
26
|
-
song.title = row.css(".chart-row__song").text
|
27
|
-
song.artist = row.css(".chart-row__artist").text.strip
|
28
|
-
song.current_rank = row.css(".chart-row__current-week").text
|
29
|
-
song.last_week_rank = row.css(".chart-row__secondary .chart-row__last-week .chart-row__value").text
|
30
|
-
song.peak_position = row.css(".chart-row__secondary .chart-row__top-spot .chart-row__value").text
|
31
|
-
song.weeks = row.css(".chart-row__secondary .chart-row__weeks-on-chart .chart-row__value").text
|
32
|
-
song
|
33
|
-
end
|
13
|
+
# build a class getter method for @@all
|
14
|
+
def self.all
|
15
|
+
@@all
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.this_week(range)
|
19
|
+
@@all["#{range-1}0".to_i, 10] #selects only 10 songs within selected range
|
34
20
|
end
|
35
21
|
|
36
22
|
# Print info for chosen song
|
data/spec.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Specifications for the CLI Assessment
|
2
2
|
|
3
3
|
Specs:
|
4
|
-
- [x] Have a CLI for interfacing with the application
|
5
|
-
- [x] Pull data from an external source
|
6
|
-
- [x] Implement both list and detail views
|
4
|
+
- [x] Have a CLI for interfacing with the application - The BillboardHot100::CLI class is chraged with the interface
|
5
|
+
- [x] Pull data from an external source - Uses Nokogiri to scrape data from billboard.com
|
6
|
+
- [x] Implement both list and detail views - Starts with a range to choose from, then displays songs to choose, which then present details on the chosen item.
|
7
7
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: billboard_hot_100
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Villicana
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/.DS_Store
|
108
108
|
- lib/billboard_hot_100.rb
|
109
109
|
- lib/billboard_hot_100/cli.rb
|
110
|
+
- lib/billboard_hot_100/scraper.rb
|
110
111
|
- lib/billboard_hot_100/song.rb
|
111
112
|
- lib/billboard_hot_100/version.rb
|
112
113
|
- spec.md
|