looperman_samples 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -1
- data/lib/looperman_samples/cli.rb +24 -22
- data/lib/looperman_samples/concerns/cli_methods.rb +36 -0
- data/lib/looperman_samples/creator.rb +13 -30
- data/lib/looperman_samples/sample.rb +17 -20
- data/lib/looperman_samples/sample_scraper.rb +3 -5
- data/lib/looperman_samples/version.rb +1 -1
- data/looperman_samples.gemspec +1 -1
- metadata +17 -3
- data/lib/looperman_samples/concerns/findable.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c67c7d616b9c5a0d129c5eb55659e5b83eae04e0aed89f62d6bf6f1379c696
|
4
|
+
data.tar.gz: 224ed66eb02c6a081d403d1e5855fd0a2be0f813cac17666489b8560fc27fc73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24b77486a35e5eeca85d2f72946803e2e175612ac1ed7698d26a7a13ffecec072ac69bc8479a336c971a782ad76915b7e143b71978bba9e468d5359277961ac5
|
7
|
+
data.tar.gz: 582c5130d0d461ad0f129b507040b8dac4ef828ce580e0930109d9ac4fd18b0f0f8637be4681b46ba0c13d17f4d9cb1008e4b18a4667a37833bb3492e6ceff85
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
looperman_samples (0.1.
|
4
|
+
looperman_samples (0.1.7)
|
5
5
|
nokogiri
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
coderay (1.1.2)
|
10
11
|
diff-lcs (1.3)
|
12
|
+
method_source (0.9.2)
|
11
13
|
mini_portile2 (2.4.0)
|
12
14
|
nokogiri (1.10.2)
|
13
15
|
mini_portile2 (~> 2.4.0)
|
16
|
+
pry (0.12.2)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
14
19
|
rake (10.4.2)
|
15
20
|
rspec (3.8.0)
|
16
21
|
rspec-core (~> 3.8.0)
|
@@ -32,6 +37,7 @@ PLATFORMS
|
|
32
37
|
DEPENDENCIES
|
33
38
|
bundler (~> 1.16)
|
34
39
|
looperman_samples!
|
40
|
+
pry (~> 0)
|
35
41
|
rake (~> 10.0)
|
36
42
|
rspec (~> 3.2)
|
37
43
|
|
@@ -1,29 +1,41 @@
|
|
1
1
|
# our CLI controller
|
2
|
+
require 'pry'
|
3
|
+
require_relative "../looperman_samples/concerns/cli_methods.rb"
|
2
4
|
|
3
5
|
class LoopermanSamples::CLI
|
4
6
|
|
7
|
+
include CliMethods::Findable
|
8
|
+
include CliMethods::Scrapeable
|
9
|
+
include CliMethods::Listable
|
10
|
+
|
11
|
+
#class variable so CLI play function can
|
12
|
+
@@sample_list = []
|
13
|
+
|
5
14
|
def call
|
6
|
-
|
15
|
+
scrape
|
7
16
|
main_menu
|
8
17
|
play
|
9
18
|
goodbye
|
10
19
|
end
|
11
20
|
|
12
21
|
def main_menu
|
22
|
+
|
13
23
|
puts "There are 25 new samples today. how would you like to browse?"
|
14
24
|
puts "1. browse samples by key"
|
15
25
|
puts "2. browse samples by tempo"
|
16
26
|
puts "3. browse samples by download count"
|
27
|
+
|
17
28
|
input = gets.strip
|
29
|
+
|
18
30
|
if input == "1"
|
19
|
-
|
20
|
-
|
31
|
+
list_by_key #prints list and sets @@sample_list variable
|
32
|
+
@@sample_list = LoopermanSamples::Sample.sort_by_key
|
21
33
|
elsif input == "2"
|
22
|
-
|
23
|
-
|
34
|
+
list_by_tempo #prints list and sets @@sample_list variable
|
35
|
+
@@sample_list = LoopermanSamples::Sample.sort_by_tempo
|
24
36
|
elsif input == "3"
|
25
|
-
|
26
|
-
|
37
|
+
list_by_downloads #prints list and sets @@sample_list variable
|
38
|
+
@@sample_list = LoopermanSamples::Sample.sort_by_download_count
|
27
39
|
else
|
28
40
|
puts "sorry, not sure what you want"
|
29
41
|
main_menu
|
@@ -36,17 +48,18 @@ class LoopermanSamples::CLI
|
|
36
48
|
loop do
|
37
49
|
puts "please enter the number of the sample you'd like to listen to or type exit:"
|
38
50
|
input = gets.strip
|
39
|
-
if input.to_i <
|
40
|
-
sample =
|
51
|
+
if input.to_i < @@sample_list.size + 1 && input.to_i > 0 #checks that input is greater than zero and less than list size
|
52
|
+
sample = @@sample_list[input.to_i - 1] #takes user input, and sets sample variable using index lookup
|
41
53
|
puts "You're listening to #{sample.title} by #{sample.creator.name}"
|
42
54
|
puts "would you like to hear more from #{sample.creator.name}? (type yes or no)"
|
43
55
|
input = gets.strip
|
44
56
|
if input == "yes"
|
45
|
-
|
57
|
+
puts "More by #{sample.creator.name}"
|
58
|
+
@@sample_list = find_all_by_creator(sample)
|
59
|
+
list_all_samples_by_creator(@@sample_list)
|
46
60
|
elsif input == "no"
|
47
61
|
main_menu
|
48
62
|
end
|
49
|
-
# puts "Ok!"
|
50
63
|
elsif input.to_i > LoopermanSamples::Sample.all.size
|
51
64
|
puts "please enter a lower number"
|
52
65
|
else
|
@@ -55,17 +68,6 @@ class LoopermanSamples::CLI
|
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
58
|
-
def more_samples_by_creator(sample)
|
59
|
-
# sets $samples_by_creator to equal a collection of samples by given creator
|
60
|
-
LoopermanSamples::SampleScraper.scrape_more_samples_by_creator(sample.creator)
|
61
|
-
# displays a numbered list of those samples
|
62
|
-
LoopermanSamples::Creator.list_all_samples_by_creator #what is this
|
63
|
-
# sets the sample list to be used in play mode
|
64
|
-
$sample_list = $samples_by_creator
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
71
|
def goodbye
|
70
72
|
puts "see you tomorrow for more samples!"
|
71
73
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CliMethods
|
2
|
+
|
3
|
+
module Findable
|
4
|
+
def find_all_by_creator(sample) #returns an array of sample objects
|
5
|
+
LoopermanSamples::SampleScraper.scrape_more_samples_by_creator(sample.creator)
|
6
|
+
sample.creator.samples
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Scrapeable
|
11
|
+
def scrape
|
12
|
+
LoopermanSamples::SampleScraper.scrape_samples
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Listable
|
17
|
+
def list_by_key
|
18
|
+
LoopermanSamples::Sample.list_samples_by_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_by_tempo
|
22
|
+
LoopermanSamples::Sample.list_samples_by_tempo
|
23
|
+
end
|
24
|
+
|
25
|
+
def list_by_downloads
|
26
|
+
LoopermanSamples::Sample.list_samples_by_download_count
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_all_samples_by_creator(sample_objects) #puts samples in numbered list
|
30
|
+
sample_objects.each_with_index do |sample, index|
|
31
|
+
puts "#{index + 1}." + " #{sample.title}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,42 +1,25 @@
|
|
1
1
|
module LoopermanSamples
|
2
|
-
|
3
2
|
class Creator
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
# creator class - a creator has a name and can have many samples
|
8
|
-
@@creators = []
|
4
|
+
attr_accessor :name, :samples
|
9
5
|
|
10
|
-
|
11
|
-
@@creators
|
12
|
-
end
|
6
|
+
@@creators = []
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@@creators << self
|
18
|
-
end
|
8
|
+
def self.all
|
9
|
+
@@creators
|
10
|
+
end
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
def initialize(name = nil)
|
13
|
+
@name = name
|
14
|
+
@samples = []
|
15
|
+
@@creators << self
|
16
|
+
end
|
25
17
|
|
26
|
-
#adds the sample into the creator's repertoire
|
27
|
-
def add_sample(sample)
|
28
|
-
sample.creator = self unless sample.creator
|
29
|
-
self.samples << sample unless self.samples.include?(sample)
|
30
|
-
end
|
31
18
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
puts "#{index + 1}." + " #{sample.title}"
|
19
|
+
def add_sample(sample)
|
20
|
+
sample.creator = self unless sample.creator
|
21
|
+
self.samples << sample unless self.samples.include?(sample)
|
36
22
|
end
|
37
|
-
end
|
38
23
|
|
39
24
|
end
|
40
|
-
|
41
|
-
|
42
25
|
end
|
@@ -3,10 +3,7 @@
|
|
3
3
|
module LoopermanSamples
|
4
4
|
class Sample
|
5
5
|
|
6
|
-
|
7
|
-
# responsible for knowing about all of the samples
|
8
|
-
|
9
|
-
attr_accessor :title, :key, :download_count, :url, :creator, :bpm, :genre
|
6
|
+
attr_accessor :title, :key, :download_count, :url, :creator, :bpm
|
10
7
|
@@all = []
|
11
8
|
|
12
9
|
def self.all
|
@@ -24,35 +21,35 @@ module LoopermanSamples
|
|
24
21
|
creator.add_sample(self)
|
25
22
|
end
|
26
23
|
|
27
|
-
def
|
28
|
-
|
29
|
-
creator.add_genre(self)
|
24
|
+
def self.sort_by_key
|
25
|
+
all.sort{|a, b| a.key <=> b.key}
|
30
26
|
end
|
31
27
|
|
32
28
|
def self.list_samples_by_key
|
33
|
-
|
34
|
-
samples_sorted_by_key = LoopermanSamples::Sample.all.sort {|a, b| a.key <=> b.key}
|
35
|
-
samples_sorted_by_key.each_with_index do |item, index|
|
29
|
+
sort_by_key.each_with_index do |item, index|
|
36
30
|
puts "#{index + 1}." + " #{item.title} - " + "#{item.key}"
|
37
31
|
end
|
38
32
|
end
|
39
33
|
|
34
|
+
def self.sort_by_tempo
|
35
|
+
all.sort{|a, b| b.bpm.to_i <=> a.bpm.to_i}
|
36
|
+
end
|
37
|
+
|
40
38
|
def self.list_samples_by_tempo
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
puts "#{index + 1}." + " #{item.title}" + "- #{item.bpm}"
|
39
|
+
sort_by_tempo.each_with_index do |item, index|
|
40
|
+
puts "#{index + 1}." + " #{item.title}" + "- #{item.bpm}"
|
41
|
+
end
|
45
42
|
end
|
43
|
+
|
44
|
+
def self.sort_by_download_count
|
45
|
+
all.sort{|a, b| b.download_count.to_i <=> a.download_count.to_i}
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.list_samples_by_download_count
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
puts "#{index + 1}." + " #{item.title}" + " - #{item.download_count} downloads"
|
53
|
-
end
|
49
|
+
sort_by_download_count.each_with_index do |item, index|
|
50
|
+
puts "#{index + 1}." + " #{item.title}" + " - #{item.download_count} downloads"
|
51
|
+
end
|
54
52
|
end
|
55
53
|
|
56
|
-
|
57
54
|
end
|
58
55
|
end
|
@@ -3,7 +3,6 @@ module LoopermanSamples
|
|
3
3
|
class SampleScraper
|
4
4
|
|
5
5
|
# uses nokogiri's output to instantiate sample and creator objects and assign them attributes, then establishes the sample-creator relationship
|
6
|
-
# there will be 25 samples from the front page of looperman
|
7
6
|
|
8
7
|
def self.scrape_samples
|
9
8
|
#goes to search for most downloaded in past 24 hours
|
@@ -31,18 +30,17 @@ module LoopermanSamples
|
|
31
30
|
#inserts the sample into the Sample.all array
|
32
31
|
Sample.all << the_sample
|
33
32
|
end
|
33
|
+
#returns all the samples
|
34
34
|
Sample.all
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.scrape_more_samples_by_creator(sample_creator)
|
38
|
-
|
37
|
+
def self.scrape_more_samples_by_creator(sample_creator) #dives into samples of a particular creator
|
38
|
+
sample_creator.samples = []
|
39
39
|
doc = Nokogiri::HTML(open("https://www.looperman.com/loops?mid=#{sample_creator.name}"))
|
40
40
|
doc.css("div#body-content").css("div div.player-wrapper").each do |sample_bundle|
|
41
41
|
the_sample = Sample.new
|
42
42
|
the_sample.title = sample_bundle.css(".player-title").text
|
43
43
|
the_sample.creator = sample_creator
|
44
|
-
$samples_by_creator << the_sample
|
45
|
-
$samples_by_creator
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
data/looperman_samples.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.16"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
-
|
33
|
+
spec.add_development_dependency "pry", '~> 0'
|
34
34
|
|
35
35
|
spec.add_dependency "nokogiri"
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: looperman_samples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Harley Rayner'"
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: nokogiri
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,7 +101,7 @@ files:
|
|
87
101
|
- bin/setup
|
88
102
|
- lib/looperman_samples.rb
|
89
103
|
- lib/looperman_samples/cli.rb
|
90
|
-
- lib/looperman_samples/concerns/
|
104
|
+
- lib/looperman_samples/concerns/cli_methods.rb
|
91
105
|
- lib/looperman_samples/creator.rb
|
92
106
|
- lib/looperman_samples/sample.rb
|
93
107
|
- lib/looperman_samples/sample_scraper.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Concerns
|
2
|
-
module Findable
|
3
|
-
def find_by_name(thing_name)
|
4
|
-
# detect stops on the first thing it finds that matches the condition and returns that value
|
5
|
-
self.all.detect do |thing|
|
6
|
-
thing.name == thing_name
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_or_create_by_name(thing_name)
|
11
|
-
if self.find_by_name(thing_name) == nil #if the song isn't in there
|
12
|
-
self.create(thing_name) #make a new song
|
13
|
-
else self.find_by_name(thing_name) != nil #if the song is in there
|
14
|
-
self.find_by_name(thing_name) # find it and return it
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def find_all_by_creator(creator)
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|