internet_near_me 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 +5 -2
- data/config/environment.rb +0 -1
- data/fixtures/vcr_cassettes/all.yml +20443 -0
- data/fixtures/vcr_cassettes/details.yml +11087 -0
- data/fixtures/vcr_cassettes/zip_code.yml +9370 -0
- data/internet_near_me.gemspec +2 -0
- data/lib/internet_near_me/cli.rb +7 -4
- data/lib/internet_near_me/internet_cafe.rb +0 -12
- data/lib/internet_near_me/scraper.rb +9 -14
- data/lib/internet_near_me/version.rb +1 -1
- metadata +33 -2
data/internet_near_me.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
spec.add_development_dependency "webmock"
|
27
29
|
end
|
data/lib/internet_near_me/cli.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
class InternetNearMe::CLI
|
2
2
|
attr_accessor :zip_code, :exit
|
3
3
|
|
4
|
+
def initialize
|
5
|
+
@exit = false
|
6
|
+
end
|
7
|
+
|
4
8
|
def call
|
5
9
|
welcome
|
6
10
|
loop do
|
@@ -16,7 +20,6 @@ class InternetNearMe::CLI
|
|
16
20
|
|
17
21
|
def welcome
|
18
22
|
puts "Welcome to internet_near_me! Enter 'exit' at any time to exit."
|
19
|
-
self.exit = false
|
20
23
|
end
|
21
24
|
|
22
25
|
def goodbye
|
@@ -27,9 +30,9 @@ class InternetNearMe::CLI
|
|
27
30
|
puts "Please enter your zip code:"
|
28
31
|
input = gets.strip
|
29
32
|
if input == 'exit'
|
30
|
-
|
33
|
+
@exit = true
|
31
34
|
else
|
32
|
-
|
35
|
+
@zip_code = input
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
@@ -53,7 +56,7 @@ class InternetNearMe::CLI
|
|
53
56
|
if input == 'back'
|
54
57
|
break
|
55
58
|
elsif input == 'exit'
|
56
|
-
|
59
|
+
@exit = true
|
57
60
|
break
|
58
61
|
else
|
59
62
|
internet_cafe = InternetNearMe::Scraper.new.scrape_details(internet_cafes[input.to_i - 1])
|
@@ -1,16 +1,4 @@
|
|
1
1
|
class InternetNearMe::InternetCafe
|
2
2
|
attr_accessor :name, :address, :price, :url, :rating, :hours, :phone,
|
3
3
|
:website, :number_of_reviews
|
4
|
-
|
5
|
-
def self.create_collection(internet_cafe_hashes)
|
6
|
-
internet_cafe_hashes.map do |internet_cafe_hash|
|
7
|
-
self.new(internet_cafe_hash)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(internet_cafe_hash)
|
12
|
-
internet_cafe_hash.each do |attribute, value|
|
13
|
-
self.send("#{attribute}=", value)
|
14
|
-
end
|
15
|
-
end
|
16
4
|
end
|
@@ -22,21 +22,16 @@ class InternetNearMe::Scraper
|
|
22
22
|
url = "http://www.yelp.com/search?find_desc=Internet+Cafes&find_loc=#{zip_code}"
|
23
23
|
doc = Nokogiri::HTML(open(url, REQUEST_HEADERS))
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
internet_cafes = []
|
26
|
+
doc.css(".search-results-content li.regular-search-result").map do |search_result|
|
27
|
+
internet_cafe = InternetNearMe::InternetCafe.new
|
28
|
+
internet_cafe.name = search_result.css("a.biz-name").text.strip
|
29
|
+
internet_cafe.address = search_result.css("address").inner_html.gsub("<br>", "\n").strip
|
30
|
+
internet_cafe.price = search_result.css(".price-range").text.strip
|
31
|
+
internet_cafe.url = search_result.css("a.biz-name").attribute("href").value
|
32
|
+
internet_cafes << internet_cafe
|
32
33
|
end
|
33
|
-
|
34
|
-
create_internet_cafes(internet_cafe_hashes)
|
34
|
+
internet_cafes
|
35
35
|
end
|
36
36
|
|
37
|
-
private
|
38
|
-
|
39
|
-
def create_internet_cafes(internet_cafe_hashes)
|
40
|
-
InternetNearMe::InternetCafe.create_collection(internet_cafe_hashes)
|
41
|
-
end
|
42
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: internet_near_me
|
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
|
- lukegrecki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
- lukegrecki@gmail.com
|
@@ -100,6 +128,9 @@ files:
|
|
100
128
|
- bin/setup
|
101
129
|
- config/environment.rb
|
102
130
|
- exe/internet_near_me
|
131
|
+
- fixtures/vcr_cassettes/all.yml
|
132
|
+
- fixtures/vcr_cassettes/details.yml
|
133
|
+
- fixtures/vcr_cassettes/zip_code.yml
|
103
134
|
- internet_near_me.gemspec
|
104
135
|
- lib/internet_near_me.rb
|
105
136
|
- lib/internet_near_me/cli.rb
|