ouch 1.0.1 → 1.0.2
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/lib/ouch/version.rb +1 -1
- data/lib/ouch.rb +21 -1
- data/test/ouch_test.rb +9 -5
- metadata +1 -2
- data/lib/ouch/info.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c15a229290624ce29f2e0b8bf1df5c541b8d324
|
4
|
+
data.tar.gz: 86bf3413a265a26433d76b40f09d8861e08e66bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 511dadb2e253561d142cce86d8aa08d5cd811607fa2a499c3953e0583a76252abc365b3ccfc9189446db8e017c852150f20b29a43465ac6a83933351b33d3c42
|
7
|
+
data.tar.gz: c0770c6912d88034f253abae375d7a1dcabde94b8cb9a293a0499c33094dd781423d083e1ff7ca9e6be7b23609e4e9404e34d4c15132fbed145876ff53c24569
|
data/lib/ouch/version.rb
CHANGED
data/lib/ouch.rb
CHANGED
@@ -3,6 +3,26 @@ require "ouch/info"
|
|
3
3
|
|
4
4
|
module Ouch
|
5
5
|
def self.find(lat: nil, lng: nil)
|
6
|
-
|
6
|
+
conn = Faraday.new("http://www.ushospitalfinder.com")
|
7
|
+
response = conn.get '/hospitals/search', { search_query: 'hospital', lat: lat, lng: lng }
|
8
|
+
page = Nokogiri::HTML.parse(response.body)
|
9
|
+
link = page.css('#list tr:first a').first
|
10
|
+
return unless link
|
11
|
+
url = link[:href]
|
12
|
+
response = conn.get(url)
|
13
|
+
page = Nokogiri::HTML.parse(response.body)
|
14
|
+
details = page.css('#detail-center p:has(b)')
|
15
|
+
data = details.inject({}) do |h, detail|
|
16
|
+
h[detail.children[1].children[0].text] = detail.children[2].text.split.join(' ').strip
|
17
|
+
h
|
18
|
+
end
|
19
|
+
|
20
|
+
{
|
21
|
+
name: data["Name:"],
|
22
|
+
address: data["Address:"],
|
23
|
+
phone: data["Phone:"],
|
24
|
+
number_of_beds: data["Number of Beds:"].to_i,
|
25
|
+
url: "http://www.ushospitalfinder.com#{url}",
|
26
|
+
}
|
7
27
|
end
|
8
28
|
end
|
data/test/ouch_test.rb
CHANGED
@@ -7,22 +7,26 @@ class TestOuch < MiniTest::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_name
|
10
|
-
@hospital
|
10
|
+
@hospital[:name].must_equal "Cedars-Sinai Medical Center"
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_address
|
14
|
-
@hospital
|
14
|
+
@hospital[:address].must_equal "8700 Beverly Boulevard Los Angeles, CA 90048-1865"
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_phone
|
18
|
-
@hospital
|
18
|
+
@hospital[:phone].must_equal "310-423-5000"
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_number_of_beds
|
22
|
-
@hospital
|
22
|
+
@hospital[:number_of_beds].must_equal 914
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_url
|
26
|
-
@hospital
|
26
|
+
@hospital[:url].must_equal 'http://www.ushospitalfinder.com/hospital/Cedars-Sinai-Medical-Center-Los-Angeles-CA'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_north_pole
|
30
|
+
Ouch.find(lat: 0, lng: 0).must_equal nil
|
27
31
|
end
|
28
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ouch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dickeyxxx
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/ouch.rb
|
83
|
-
- lib/ouch/info.rb
|
84
83
|
- lib/ouch/version.rb
|
85
84
|
- ouch.gemspec
|
86
85
|
- test/ouch_test.rb
|
data/lib/ouch/info.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
module Ouch
|
5
|
-
class Info
|
6
|
-
def initialize(lat: nil, lng: nil)
|
7
|
-
conn = Faraday.new("http://www.ushospitalfinder.com")
|
8
|
-
response = conn.get '/hospitals/search', { search_query: 'hospital', lat: lat, lng: lng }
|
9
|
-
page = Nokogiri::HTML.parse(response.body)
|
10
|
-
@url = page.css('#list tr:first a')[0][:href]
|
11
|
-
response = conn.get(@url)
|
12
|
-
page = Nokogiri::HTML.parse(response.body)
|
13
|
-
details = page.css('#detail-center p:has(b)')
|
14
|
-
@data = details.inject({}) do |data, detail|
|
15
|
-
data[detail.children[1].children[0].text] = detail.children[2].text.split.join(' ').strip
|
16
|
-
data
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def name
|
21
|
-
@data["Name:"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def address
|
25
|
-
@data["Address:"]
|
26
|
-
end
|
27
|
-
|
28
|
-
def phone
|
29
|
-
@data["Phone:"]
|
30
|
-
end
|
31
|
-
|
32
|
-
def number_of_beds
|
33
|
-
@data["Number of Beds:"].to_i
|
34
|
-
end
|
35
|
-
|
36
|
-
def url
|
37
|
-
"http://www.ushospitalfinder.com#{@url}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|