eaternet 1.3.9 → 1.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 +4 -4
- data/lib/eaternet.rb +1 -0
- data/lib/eaternet/agencies/lives2.rb +93 -0
- data/lib/eaternet/version.rb +1 -1
- data/test/eaternet/agencies/lives2_test.rb +95 -0
- data/test/test_helper.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e1375032849d789bc66d07c270c9cbbd1359d2
|
4
|
+
data.tar.gz: 816728cbcb1c031b7ec8317696c4034e7a73498f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23952a31ca0a0aae9bc48ca4264dd0d80cc0929627b3fe857c45beb4727161ae8e2b0f59b01182d0cd8c8f25ec6b53f36e2e668731276a99beb58682e5453b39
|
7
|
+
data.tar.gz: 5e0e4721edabd70975f6c0ec9bde85e9a03929e7acf45289069e5a8487a483447b5e1ab52c085d389bb7ee21a7e2b604fe417468b8f62bdacca36919d112d11d
|
data/lib/eaternet.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
require 'eaternet/lives_1_0/adapter'
|
5
|
+
require 'eaternet/lives_1_0/csv_parser'
|
6
|
+
require 'eaternet/loggable'
|
7
|
+
require 'eaternet/util'
|
8
|
+
|
9
|
+
module Eaternet
|
10
|
+
module Agencies
|
11
|
+
class Lives2 < Eaternet::Lives_1_0::Adapter
|
12
|
+
include Eaternet::Loggable
|
13
|
+
include Eaternet::Lives_1_0::CsvParser
|
14
|
+
|
15
|
+
def initialize(feed_url:, municipality_name:, municipality_url:, contact_email:)
|
16
|
+
@feed_url = feed_url
|
17
|
+
@municipality_name = municipality_name
|
18
|
+
@municipality_url = municipality_url
|
19
|
+
@contact_email = contact_email
|
20
|
+
end
|
21
|
+
|
22
|
+
def businesses
|
23
|
+
convert csv: 'businesses.csv', to_type: :business
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspections
|
27
|
+
convert csv: 'inspections.csv', to_type: :inspection
|
28
|
+
end
|
29
|
+
|
30
|
+
def violations
|
31
|
+
convert csv: 'violations.csv', to_type: :violation
|
32
|
+
end
|
33
|
+
|
34
|
+
def feed_info
|
35
|
+
Eaternet::Lives_1_0::FeedInfo.new do |fi|
|
36
|
+
fi.feed_date = Date.today
|
37
|
+
fi.feed_version = '2.0'
|
38
|
+
fi.municipality_name = @municipality_name
|
39
|
+
fi.municipality_url = @municipality_url
|
40
|
+
fi.contact_email = @contact_email
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def adapter_name
|
45
|
+
@municipality_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def zip_file_url
|
49
|
+
@feed_url
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def business(csv_row)
|
55
|
+
Eaternet::Lives_1_0::Business.new do |b|
|
56
|
+
csv_row.headers.each do |header|
|
57
|
+
b.send("#{header.downcase}=", csv_row[header])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspection(csv_row)
|
63
|
+
Eaternet::Lives_1_0::Inspection.new do |b|
|
64
|
+
csv_row.headers.each do |header|
|
65
|
+
b.send("#{header.downcase}=", csv_row[header])
|
66
|
+
b.date = Date.parse(csv_row['date'])
|
67
|
+
b.score = csv_row['score'].to_i
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def violation(csv_row)
|
73
|
+
Eaternet::Lives_1_0::Violation.new do |b|
|
74
|
+
csv_row.headers.each do |header|
|
75
|
+
b.send("#{header.downcase}=", csv_row[header])
|
76
|
+
b.date = Date.parse(csv_row['date'])
|
77
|
+
b.description = fix(description: csv_row['description'])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def fix(description:)
|
83
|
+
# Remove bracketed violation facts, non-conforming to LIVES
|
84
|
+
return description unless description =~ /^([^\[]+)/
|
85
|
+
$1.strip
|
86
|
+
end
|
87
|
+
|
88
|
+
def csv_reader(path:)
|
89
|
+
CSV.new(open(path, encoding: 'ISO-8859-1'), headers: true)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/eaternet/version.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
require 'eaternet'
|
4
|
+
|
5
|
+
class Lives2Test < Minitest::Test
|
6
|
+
# Instantiating as an app developer would:
|
7
|
+
@@l2 = Eaternet::Lives2.new(
|
8
|
+
feed_url: 'https://extxfer.sfdph.org/food/SFBusinesses.zip',
|
9
|
+
municipality_name: 'San Francisco',
|
10
|
+
municipality_url: 'http://www.sfgov.org',
|
11
|
+
contact_email: 'richard.lee@sfdph.org'
|
12
|
+
)
|
13
|
+
|
14
|
+
#
|
15
|
+
# Businesses
|
16
|
+
#
|
17
|
+
|
18
|
+
def test_businesses_returns_an_enumerator_of_business
|
19
|
+
VCR.use_cassette(L2_CASSETTE) do
|
20
|
+
assert enumerable_of? Eaternet::Lives_1_0::Business, @@l2.businesses
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_businesses_returns_lives_attributes
|
25
|
+
VCR.use_cassette(L2_CASSETTE) do
|
26
|
+
b = @@l2.businesses.first
|
27
|
+
assert_equal '10', b.business_id
|
28
|
+
assert_equal 'TIRAMISU KITCHEN', b.name
|
29
|
+
assert_equal '033 BELDEN PL', b.address
|
30
|
+
assert_equal 'San Francisco', b.city
|
31
|
+
assert_equal '94104', b.postal_code
|
32
|
+
assert_equal 'CA', b.state
|
33
|
+
assert_equal 37.791116, b.latitude
|
34
|
+
assert_equal -122.403816, b.longitude
|
35
|
+
assert_equal '+14154217044', b.phone_number
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Inspections
|
41
|
+
#
|
42
|
+
|
43
|
+
def test_inspections_returns_an_enumerable_of_inspection
|
44
|
+
VCR.use_cassette(L2_CASSETTE) do
|
45
|
+
assert enumerable_of? Eaternet::Lives_1_0::Inspection, @@l2.inspections
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_inspections_returns_lives_attributes
|
50
|
+
VCR.use_cassette(L2_CASSETTE) do
|
51
|
+
chosen_inspection = @@l2.inspections
|
52
|
+
.select { |i| i.business_id == '19' && i.date == Date.new(2016, 5, 13) }
|
53
|
+
.first
|
54
|
+
raise "Couldn't find the chosen inspection" if chosen_inspection.nil?
|
55
|
+
assert_equal 94, chosen_inspection.score
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Violations
|
61
|
+
#
|
62
|
+
|
63
|
+
def test_violations_returns_an_enumerable_of_violation
|
64
|
+
VCR.use_cassette(L2_CASSETTE) do
|
65
|
+
assert enumerable_of? Eaternet::Lives_1_0::Violation, @@l2.violations
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# TODO: Fix this test
|
70
|
+
# def test_violations_returns_lives_attributes
|
71
|
+
# VCR.use_cassette(L2_CASSETTE) do
|
72
|
+
# v = @@l2.violations.first
|
73
|
+
# assert_equal '10', v.business_id
|
74
|
+
# assert_equal Date.new(2014, 7, 29), v.date
|
75
|
+
# assert_equal nil, v.code
|
76
|
+
# assert_match /^Insufficient hot water or running water$/, v.description
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
|
80
|
+
#
|
81
|
+
# metadata
|
82
|
+
#
|
83
|
+
|
84
|
+
def test_implements_feed_info
|
85
|
+
assert_instance_of Eaternet::Lives_1_0::FeedInfo, @@l2.feed_info
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Other
|
90
|
+
#
|
91
|
+
|
92
|
+
# def test_handles_file_encoding
|
93
|
+
# refute_nil @@l2.businesses.to_a
|
94
|
+
# end
|
95
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eaternet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
@@ -254,6 +254,7 @@ files:
|
|
254
254
|
- eaternet.gemspec
|
255
255
|
- lib/eaternet.rb
|
256
256
|
- lib/eaternet/agencies/austin.rb
|
257
|
+
- lib/eaternet/agencies/lives2.rb
|
257
258
|
- lib/eaternet/agencies/multco.rb
|
258
259
|
- lib/eaternet/agencies/multco_lib/misc.rb
|
259
260
|
- lib/eaternet/agencies/nyc.rb
|
@@ -278,6 +279,7 @@ files:
|
|
278
279
|
- lib/eaternet/version.rb
|
279
280
|
- lib/ext/enumerator.rb
|
280
281
|
- test/eaternet/agencies/austin_test.rb
|
282
|
+
- test/eaternet/agencies/lives2_test.rb
|
281
283
|
- test/eaternet/agencies/multco_test.rb
|
282
284
|
- test/eaternet/agencies/nyc_test.rb
|
283
285
|
- test/eaternet/agencies/sf_test.rb
|
@@ -321,6 +323,7 @@ specification_version: 4
|
|
321
323
|
summary: Regional adapters for restaurant health scores
|
322
324
|
test_files:
|
323
325
|
- test/eaternet/agencies/austin_test.rb
|
326
|
+
- test/eaternet/agencies/lives2_test.rb
|
324
327
|
- test/eaternet/agencies/multco_test.rb
|
325
328
|
- test/eaternet/agencies/nyc_test.rb
|
326
329
|
- test/eaternet/agencies/sf_test.rb
|