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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 997e94fa9974dbeebb5b3801a887f12464b99dba
4
- data.tar.gz: fa94cfdaae4a47a90c6baea84f13c7179788b8fa
3
+ metadata.gz: '08521431a492c0c67e04977c4042b69f9ccce5c5'
4
+ data.tar.gz: 81c336e3d2eae45e3592385308d6e6604fcb2beb
5
5
  SHA512:
6
- metadata.gz: ad73d2c2a31a1dea3fc4eceae8a989505c9c52321664237c8f660b893ac1b0ede1974c611bdaa92e2461c8ba45b52fe6940d03ee1746df5b82b4a91bd911a6a7
7
- data.tar.gz: 2a9da1d2837cfda2d99f1833f2f2df6a82cc00c0bebd33f8e1d0da7a5af5c907933cc472543d7a4cb2f555bce1ea83d376f612db8ea63a6e11a24a725feed5c6
6
+ metadata.gz: 17d4f772778383f825e65b7c99caf4f3f1579868242e02c41816d5848cb023dcff7bd5f732f01430761abb425f3fcad23ba12e0c13b1ce4b53ea0d50c65d2db7
7
+ data.tar.gz: 695d828da1f143521fc6c1ba65a4b393aa8431774f1fc4fdad68faf534cee3ad4d2ef882f4c2eae1e3b5eea98987b87b86d01af87088626df62ca75d16a1f12f
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Run 'bin/billboard_hot_100' for an interactive prompt that will allow you to experiment with the gem.
24
24
 
25
25
  ## Development
26
26
 
@@ -2,6 +2,7 @@ class BillboardHot100::CLI
2
2
 
3
3
  # Main instance method
4
4
  def run
5
+ BillboardHot100::Scraper.scrape_songs
5
6
  main_menu
6
7
  select_song
7
8
  end
@@ -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 self.this_week(range)
7
- @@all ||= self.scrape_songs
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
- # Scrape songs from https://www.billboard.com/charts/hot-100
16
- def self.scrape_songs
17
- page_html = Nokogiri::HTML(open("https://www.billboard.com/charts/hot-100"))
18
- chart = page_html.css(".chart-data .container")
19
-
20
- #Iterate through the first 100 rows of the billboard chart
21
- #Create instances of the Song class during each iteration
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
@@ -1,3 +1,3 @@
1
1
  module BillboardHot100
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-14 00:00:00.000000000 Z
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