ouch 1.0.1 → 1.0.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: 3eb184edcb1533b580449ffd0cee1c58f3751fdd
4
- data.tar.gz: b076f9e5dfee150269e08ef61fd4c8c0f40a374e
3
+ metadata.gz: 9c15a229290624ce29f2e0b8bf1df5c541b8d324
4
+ data.tar.gz: 86bf3413a265a26433d76b40f09d8861e08e66bb
5
5
  SHA512:
6
- metadata.gz: c016de10a58900854a59330ab79a0bc801eb0e7d29f6240d834c18bac48f187a53a05dc2c40a78d58b1ffd6131a6cca4652b4d14328e6b6cb074d805431aa220
7
- data.tar.gz: b6899fdd430dfb7a945a709ba338698864503308f600fbba634bad72f76d29d03cedd1dcaee1c8899f4011a5932cc5a00dfef91c626c1876943bb5894335f04c
6
+ metadata.gz: 511dadb2e253561d142cce86d8aa08d5cd811607fa2a499c3953e0583a76252abc365b3ccfc9189446db8e017c852150f20b29a43465ac6a83933351b33d3c42
7
+ data.tar.gz: c0770c6912d88034f253abae375d7a1dcabde94b8cb9a293a0499c33094dd781423d083e1ff7ca9e6be7b23609e4e9404e34d4c15132fbed145876ff53c24569
data/lib/ouch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ouch
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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
- Info.new(lat: lat, lng: lng)
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.name.must_equal "Cedars-Sinai Medical Center"
10
+ @hospital[:name].must_equal "Cedars-Sinai Medical Center"
11
11
  end
12
12
 
13
13
  def test_address
14
- @hospital.address.must_equal "8700 Beverly Boulevard Los Angeles, CA 90048-1865"
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.phone.must_equal "310-423-5000"
18
+ @hospital[:phone].must_equal "310-423-5000"
19
19
  end
20
20
 
21
21
  def test_number_of_beds
22
- @hospital.number_of_beds.must_equal 914
22
+ @hospital[:number_of_beds].must_equal 914
23
23
  end
24
24
 
25
25
  def test_url
26
- @hospital.url.must_equal 'http://www.ushospitalfinder.com/hospital/Cedars-Sinai-Medical-Center-Los-Angeles-CA'
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.1
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