headphones-buyers-guide-cli-gem 0.1.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
|
+
SHA256:
|
3
|
+
metadata.gz: 5a767706a4e281ac67eeb41b9779940e8602062b56caa27f8a2f26e82cebe1c1
|
4
|
+
data.tar.gz: 56d43722c52c1cbde34730ecd2192eff53ee5639f3a8eb209040da33d062f8dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1195b6d6bce295efbccde4597ff18769f055ee025c66526fe0dca80793245c3f0ca5ad605f71827d0b0df77fc83e9e497ba825d5f5791ef715391efd943091c
|
7
|
+
data.tar.gz: 6c901c632a61926074ccaa0ac5bee657903f020dfa07491f69cba59c43468b8789db1db1ad784fb3d62ec4760e12712ec113ea335fc7fba671ff02e0d0ddf70f
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'pry'
|
2
|
+
class Headphones::CLI
|
3
|
+
|
4
|
+
def call
|
5
|
+
greeting
|
6
|
+
start
|
7
|
+
goodby
|
8
|
+
end
|
9
|
+
|
10
|
+
def greeting
|
11
|
+
puts(<<~EOT)
|
12
|
+
Welcome to the Headphone Buyer's Guide
|
13
|
+
---------------------------
|
14
|
+
To begin choose a headphone type, to quit type exit"
|
15
|
+
1. In-ear
|
16
|
+
2. Over-ear
|
17
|
+
3. On-ear
|
18
|
+
EOT
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def start
|
23
|
+
in_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/earbuds/")
|
24
|
+
over_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/over-the-ear/")
|
25
|
+
on_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/on-ear/")
|
26
|
+
|
27
|
+
input = nil
|
28
|
+
|
29
|
+
while input != "exit" || !input.to_i.between?(1,3)
|
30
|
+
input = gets.strip
|
31
|
+
case input
|
32
|
+
when "1"
|
33
|
+
select_headphone(in_ear_array)
|
34
|
+
when "2"
|
35
|
+
select_headphone(over_ear_array)
|
36
|
+
when "3"
|
37
|
+
select_headphone(on_ear_array)
|
38
|
+
when "exit"
|
39
|
+
goodby
|
40
|
+
else
|
41
|
+
puts (<<~EOT).colorize(:red)
|
42
|
+
Please choose valid number or type exit:
|
43
|
+
1. In-ear
|
44
|
+
2. Over-ear
|
45
|
+
3. On-ear
|
46
|
+
EOT
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def select_headphone(array)
|
53
|
+
|
54
|
+
puts "Here are the top headphones in the catagory:".colorize(:blue)
|
55
|
+
puts " "
|
56
|
+
generate_list(array)
|
57
|
+
puts "Choose Headphone Number for More Info or Type exit.".colorize(:blue)
|
58
|
+
input = nil
|
59
|
+
|
60
|
+
while input != "exit" || !input.to_i.between?(1,array.length)
|
61
|
+
input = gets.strip
|
62
|
+
if input.to_i.between?(1, array.length)
|
63
|
+
more_info(input, array)
|
64
|
+
again
|
65
|
+
elsif input.downcase == "exit"
|
66
|
+
exit
|
67
|
+
else
|
68
|
+
puts "Please choose valid number or type exit".colorize(:red)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def generate_list(array)
|
74
|
+
array.each.with_index do |h, i|
|
75
|
+
puts "#{i + 1}. #{array[i][:name].colorize(:green)} #{array[i][:price]} \n #{array[i][:description]}"
|
76
|
+
puts "#{array[i][:rating]}"
|
77
|
+
puts " "
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def more_info(input, array)
|
82
|
+
Headphones::Scraper.more_info(array[input.to_i - 1][:url])
|
83
|
+
end
|
84
|
+
|
85
|
+
def again
|
86
|
+
puts "Do you want to search again? y/n"
|
87
|
+
input = nil
|
88
|
+
while input != "n"
|
89
|
+
input = gets.strip
|
90
|
+
if input == "y"
|
91
|
+
call
|
92
|
+
else
|
93
|
+
puts "Do you want to search again? y/n"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
goodby
|
97
|
+
end
|
98
|
+
|
99
|
+
def goodby
|
100
|
+
puts "Goodby and good luck finding the perfect hedphones!"
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Headphones::Scraper
|
2
|
+
|
3
|
+
def self.list(url)
|
4
|
+
doc = Nokogiri::HTML(open(url)).css("#rbContent div.bestListing ul li div.itemWrap")
|
5
|
+
|
6
|
+
headphones_array =[]
|
7
|
+
|
8
|
+
doc.each do |headphone|
|
9
|
+
h_name = headphone.css("h5").text
|
10
|
+
h_price = headphone.css(".price").text
|
11
|
+
h_url = "https://www.cnet.com#{doc.css(".review").attribute("href").value}"
|
12
|
+
h_rating = headphone.css(".subRatings")[0].attribute("aria-label").value
|
13
|
+
h_description = headphone.css(".dek").text
|
14
|
+
|
15
|
+
headphones_array << {name: h_name, price: h_price, url: h_url, rating: h_rating, description: h_description}
|
16
|
+
end
|
17
|
+
headphones_array
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.more_info(url)
|
21
|
+
doc = Nokogiri::HTML(open(url)).css(".quickInfo")
|
22
|
+
|
23
|
+
puts(<<~EOT)
|
24
|
+
The Good
|
25
|
+
--------
|
26
|
+
#{doc.css(".theGood").text.split("The Good")[1]}
|
27
|
+
|
28
|
+
The Bad
|
29
|
+
_______
|
30
|
+
#{doc.css(".theBad").text.split("The Bad")[1]}
|
31
|
+
|
32
|
+
The Bottom bottom_line
|
33
|
+
______________________
|
34
|
+
#{doc.css(".theBottomLine").text}
|
35
|
+
|
36
|
+
EOT
|
37
|
+
puts "For full review : #{url}".colorize(:blue)
|
38
|
+
puts " "
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: headphones-buyers-guide-cli-gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ariel Feingold
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-15 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- feingold.ariel@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- "./lib/headphones-buyers-guide-cli-gem/cli.rb"
|
49
|
+
- "./lib/headphones-buyers-guide-cli-gem/scraper.rb"
|
50
|
+
- "./lib/headphones-buyers-guide-cli-gem/version.rb"
|
51
|
+
- lib/headphones-buyers-guide-cli-gem.rb
|
52
|
+
homepage: http://rubygems.org
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata:
|
56
|
+
allowed_push_host: https://rubygems.org
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.7.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: This App scrapes the c|net for best hedphones and prsents it to the user.
|
77
|
+
test_files: []
|