eaternet 0.3.17 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f074020bfc866a9df8fe3953bbe48d11e2f5ac5
4
- data.tar.gz: b906df3d38e0a74369c536739cc02259236864c3
3
+ metadata.gz: a90f995b06ed13d80581580cf7e3c2a4cc82264f
4
+ data.tar.gz: c797ce791fd07fe381a0de8c7c85e0d449b48fb8
5
5
  SHA512:
6
- metadata.gz: f86771cbda0f02d37b6d11bd0d18453a2ee1feeb3226b55b640169d596532a6928f6c03d8f1b58c20642c6d260ea86b48de1c7c2352b71dc3f8fa9b23e9823f8
7
- data.tar.gz: 4626b39553c79847e2722729a9643218835b8fbd5cd1cc71729c7059be853ffd4322b53fdd1dc915e8e6b6cc522af5ae77985fe9b9e048b33209939d459dd093
6
+ metadata.gz: c882a43aeaca5fc990ebc0a2f7c0414cf295db053b715307aeabbfcb84b6224d024aa411b448fed558ec2796e2a52876b6baea87624362fad1cd49375361afd2
7
+ data.tar.gz: 093cdf2ec98b5a6dcae3d781fd25138802fd5e6d93d80dd17ab3fc5102fd1acd8f5a76f906009d5782a26f1db7b212b707d2213c50a4c4763e0b9edb4a7f5017
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_runtime_dependency 'activemodel', '~> 4.2.1'
33
33
  spec.add_runtime_dependency 'rubyzip'
34
+ spec.add_runtime_dependency 'httparty'
34
35
  end
@@ -1,5 +1,6 @@
1
- require 'eaternet/agencies/snhd'
2
1
  require 'eaternet/agencies/nyc'
2
+ require 'eaternet/agencies/snhd'
3
+ require 'eaternet/agencies/snhd_lives'
3
4
 
4
5
  module Eaternet
5
6
  # Make the actual adapters easily available
@@ -7,6 +8,7 @@ module Eaternet
7
8
  #
8
9
  # * `Eaternet::Nyc`
9
10
  # * `Eaternet::Snhd`
11
+ # * `Eaternet::SnhdLives`
10
12
  include Eaternet::Agencies
11
13
  end
12
14
 
@@ -55,11 +55,18 @@ module Eaternet
55
55
  # (see Eaternet::Prototype::AbstractAdapter#inspections)
56
56
  def inspections
57
57
  lazy_csv_map('restaurant_inspections.csv') do |row|
58
+ if row['violations']
59
+ violations = row['violations'].split(',')
60
+ else
61
+ violations = []
62
+ end
58
63
  Eaternet::Prototype::InspectionData.new(
59
64
  orig_key: row['serial_number'],
60
65
  business_orig_key: row['permit_number'],
61
66
  score: row['inspection_grade'],
62
- date: row['inspection_date']
67
+ demerits: row['inspection_demerits'],
68
+ date: row['inspection_date'],
69
+ violations: violations
63
70
  )
64
71
  end
65
72
  end
@@ -0,0 +1,83 @@
1
+ require 'date'
2
+ require 'eaternet/loggable'
3
+
4
+ module Eaternet
5
+ module Agencies
6
+ class SnhdLives < Eaternet::Lives_1_0::Adapter
7
+ include Eaternet::Lives_1_0
8
+ include Eaternet::Loggable
9
+
10
+ def initialize
11
+ @prototype = Eaternet::Agencies::Snhd.new
12
+ end
13
+
14
+ def businesses
15
+ @prototype.businesses
16
+ .map { |proto|
17
+ Business.new do |b|
18
+ b.business_id = proto.orig_key
19
+ b.name = proto.name
20
+ b.address = proto.address
21
+ b.city = proto.city
22
+ b.postal_code = proto.zipcode
23
+ b.state = 'NV'
24
+ end
25
+ }
26
+ end
27
+
28
+ def inspections
29
+ @prototype.inspections
30
+ .map { |proto|
31
+ Inspection.new do |i|
32
+ i.business_id = proto.business_orig_key
33
+ i.score = proto.demerits.nil? ? nil : 100 - proto.demerits.to_i
34
+ i.date = Date.parse(proto.date)
35
+ end
36
+ }
37
+ end
38
+
39
+ def violations
40
+ @violations ||= _violations
41
+ end
42
+
43
+ def feed_info
44
+ FeedInfo.new do |fi|
45
+ fi.feed_date = Date.today
46
+ fi.feed_version = '1.0'
47
+ fi.municipality_name = 'Southern Nevada'
48
+ fi.municipality_url = 'http://southernnevadahealthdistrict.org/restaurants/index.php'
49
+ fi.contact_email = 'environmentalhealth@snhdmail.org'
50
+ end
51
+ end
52
+
53
+ def legends
54
+ []
55
+ end
56
+
57
+ def _violations
58
+ violation_kinds = {}
59
+ @prototype.violation_kinds.to_a.each do |vk|
60
+ violation_kinds[vk.orig_key] = vk
61
+ end
62
+
63
+ result = []
64
+
65
+ @prototype.inspections.each do |proto_inspection|
66
+ proto_inspection.violations.each do |kind_id|
67
+ begin
68
+ result << Violation.new do |v|
69
+ v.business_id = proto_inspection.business_orig_key
70
+ v.date = Date.parse(proto_inspection.date)
71
+ v.code = violation_kinds[kind_id].code
72
+ v.description = violation_kinds[kind_id].description
73
+ end
74
+ rescue NoMethodError => e
75
+ logger.debug "Error creating violation kind #{kind_id} for inspection #{proto_inspection.orig_key}: #{e}"
76
+ end
77
+ end
78
+ end
79
+ result
80
+ end
81
+ end
82
+ end
83
+ end
@@ -50,7 +50,7 @@ module Eaternet
50
50
  # @required No
51
51
  # @return [Enumerable<Legend>]
52
52
  def legends
53
- fails 'Optionally override this to return an Enumerable of Legend'
53
+ fail 'Optionally override this to return an Enumerable of Legend'
54
54
  end
55
55
  end
56
56
  end
@@ -61,13 +61,15 @@ module Eaternet
61
61
  #:nodoc:
62
62
  class InspectionData
63
63
  # @return [String]
64
- attr_reader :orig_key, :business_orig_key, :score, :date
64
+ attr_reader :orig_key, :business_orig_key, :score, :date, :demerits, :violations
65
65
 
66
- def initialize(orig_key:, business_orig_key:, score:, date:)
66
+ def initialize(orig_key:, business_orig_key:, score:, date:, demerits: nil, violations: [])
67
67
  @orig_key = orig_key
68
68
  @business_orig_key = business_orig_key
69
69
  @score = score
70
70
  @date = date
71
+ @demerits = demerits
72
+ @violations = violations
71
73
  end
72
74
 
73
75
  def to_s
@@ -1,6 +1,6 @@
1
1
  require 'base64'
2
- require 'open-uri'
3
2
  require 'zip'
3
+ require 'httparty'
4
4
 
5
5
  module Eaternet
6
6
  module Util
@@ -43,7 +43,7 @@ module Eaternet
43
43
  # @param [String] dest pathname in which to save the file
44
44
  # @return [File] the file
45
45
  def self.download(source:, dest:)
46
- File.open(dest, 'wb') { |file| file << open(source).read }
46
+ File.open(dest, 'wb') { |file| file << HTTParty.get(source).body }
47
47
  end
48
48
 
49
49
  # Extract a Zip archive.
@@ -1,3 +1,3 @@
1
1
  module Eaternet
2
- VERSION = '0.3.17'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+ require 'eaternet'
3
+
4
+ class SnhdLivesTest < Minitest::Test
5
+ @@snhd = Eaternet::SnhdLives.new
6
+
7
+ #
8
+ # Businesses
9
+ #
10
+
11
+ def test_businesses_returns_an_enumerator_of_business
12
+ VCR.use_cassette(SNHD_CASSETTE) do
13
+ assert enumerable_of? Eaternet::Lives_1_0::Business, @@snhd.businesses
14
+ end
15
+ end
16
+
17
+ def test_businesses_returns_lives_attributes
18
+ VCR.use_cassette(SNHD_CASSETTE) do
19
+ b = @@snhd.businesses.first
20
+ assert_equal 'PR0000002', b.business_id
21
+ assert_equal "McDonald's #3549 D HOTEL", b.name
22
+ assert_equal '301 Fremont St', b.address
23
+ assert_equal 'Las Vegas', b.city
24
+ assert_equal '89101-5600', b.postal_code
25
+ assert_equal 'NV', b.state
26
+ end
27
+ end
28
+
29
+ #
30
+ # Inspections
31
+ #
32
+
33
+ def test_inspections_returns_an_enumerable_of_inspection
34
+ VCR.use_cassette(SNHD_CASSETTE) do
35
+ assert enumerable_of? Eaternet::Lives_1_0::Inspection, @@snhd.inspections
36
+ end
37
+ end
38
+
39
+ def test_inspections_returns_lives_attributes
40
+ VCR.use_cassette(SNHD_CASSETTE) do
41
+ i = @@snhd.inspections.first(6).last
42
+ assert_equal 'PR0000411', i.business_id
43
+ assert_equal Date.new(1994, 04, 15), i.date
44
+ assert_equal 96, i.score
45
+ end
46
+ end
47
+
48
+ #
49
+ # Violations
50
+ #
51
+
52
+ def test_violations_returns_an_enumerable_of_violation
53
+ VCR.use_cassette(SNHD_CASSETTE) do
54
+ assert enumerable_of? Eaternet::Lives_1_0::Violation, @@snhd.violations
55
+ end
56
+ end
57
+
58
+ def test_violations_returns_lives_attributes
59
+ VCR.use_cassette(SNHD_CASSETTE) do
60
+ v = @@snhd.violations.first
61
+ assert_equal 'PR0000411', v.business_id
62
+ assert_equal Date.new(1994, 4, 13), v.date
63
+ assert_equal '8', v.code
64
+ assert_match /hazardous salads/, v.description
65
+ end
66
+ end
67
+
68
+ #
69
+ # metadata
70
+ #
71
+
72
+ def test_implements_feed_info
73
+ assert_instance_of Eaternet::Lives_1_0::FeedInfo, @@snhd.feed_info
74
+ end
75
+ end
@@ -3,7 +3,6 @@ require 'eaternet'
3
3
 
4
4
  # Tests for the Southern Nevada Health District / Las Vegas
5
5
 
6
- SNHD_CASSETTE = 'snhd'
7
6
 
8
7
  class SnhdAdapterTest < Minitest::Test
9
8
  @@snhd = Eaternet::Snhd.new
@@ -16,3 +16,5 @@ def enumerable_of?(a_class, obj)
16
16
  assert_kind_of Enumerable, obj
17
17
  assert_kind_of a_class, obj.first
18
18
  end
19
+
20
+ SNHD_CASSETTE = 'snhd'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eaternet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.17
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: httparty
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: A framework for easily retrieving a region's health scores in a standardized
168
182
  way.
169
183
  email:
@@ -186,6 +200,7 @@ files:
186
200
  - lib/eaternet/agencies/nyc.rb
187
201
  - lib/eaternet/agencies/snhd.rb
188
202
  - lib/eaternet/agencies/snhd_config.rb
203
+ - lib/eaternet/agencies/snhd_lives.rb
189
204
  - lib/eaternet/lives_1_0.rb
190
205
  - lib/eaternet/lives_1_0/adapter.rb
191
206
  - lib/eaternet/lives_1_0/business.rb
@@ -201,6 +216,7 @@ files:
201
216
  - lib/eaternet/version.rb
202
217
  - lib/ext/enumerator.rb
203
218
  - test/eaternet/agencies/nyc_test.rb
219
+ - test/eaternet/agencies/snhd_lives_test.rb
204
220
  - test/eaternet/agencies/snhd_test.rb
205
221
  - test/eaternet/eaternet_test.rb
206
222
  - test/eaternet/lives_1_0/business_test.rb
@@ -239,6 +255,7 @@ specification_version: 4
239
255
  summary: Regional adapters for restaurant health scores
240
256
  test_files:
241
257
  - test/eaternet/agencies/nyc_test.rb
258
+ - test/eaternet/agencies/snhd_lives_test.rb
242
259
  - test/eaternet/agencies/snhd_test.rb
243
260
  - test/eaternet/eaternet_test.rb
244
261
  - test/eaternet/lives_1_0/business_test.rb