eaternet 0.3.10 → 0.3.11

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: aef5964ed9df66f15b67479666a138c217dc4e2e
4
- data.tar.gz: 7b5576bb97873aaa7a945fefb8fad5b73f950878
3
+ metadata.gz: 11257485cfdcbda82f42ae36c646ebfc9616203d
4
+ data.tar.gz: 9f3bbe15c16db1bc73527cbb25aa69c4421ea630
5
5
  SHA512:
6
- metadata.gz: 41657aba33ed69e9f91cde7cdf46e6f8a75a777fdfd94beaa56bf1241c414a8a83143619a21140dc45502413a5895dec4a2663e9d660d643aa56b0e975673527
7
- data.tar.gz: 35357963b80e1dfe1a01010e6a952dff5ff0cc2ffe06432b499c6217b020d747a639d0c35e9daa064eaaa734929d1775bf829f95c8bc9e75676fd6bc77f48f36
6
+ metadata.gz: 9bd3634278276974dcecb89c48f1285ff652245dd968d8be8349b7063b853c8acfa6af8c5e7fcea6bb2703c50e4dcd3e2cf993784ff5eff92578f8f327de9e4c
7
+ data.tar.gz: 2484a3f65c718bd457b6ee56a6c40bb64aa4326950723ee59198c1b05f52f336bde72f3b1035c246638bb606483023c832a81573d5c0bb48e9ae47e4a47cbbf4
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --name-tag required:"Required"
1
+ --no-private --markup markdown --name-tag required:"Required"
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'minitest-utils', git: 'git@github.com:dogweather/minitest-utils.git'
3
+ gem 'minitest-utils', git: 'https://github.com/dogweather/minitest-utils.git'
4
4
  gemspec
data/Guardfile CHANGED
@@ -5,7 +5,7 @@
5
5
  # directories %w(app lib config test spec features)
6
6
 
7
7
  ## Uncomment to clear the screen before every task
8
- # clearing :on
8
+ clearing :on
9
9
  guard :minitest do
10
10
  watch(%r{^test/(.*)_test\.rb$})
11
11
  watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
@@ -13,37 +13,73 @@ require 'eaternet/loggable'
13
13
 
14
14
  module Eaternet
15
15
  module Agencies
16
- # A LIVES 1.0 data source for New York City.
16
+ # A data source for New York City food service health inspections. It
17
+ # retrieves the latest info from the official source and makes it easy
18
+ # to work with.
17
19
  #
18
- # @example Print all the restaurant names in New York City.
20
+ # This library conforms to the
21
+ # [LIVES 1.0 standard](http://www.yelp.com/healthscores) developed by
22
+ # Yelp and the cities of San Francisco and New York.
23
+ #
24
+ # @example Print the names of all the restaurants in New York City
19
25
  # nyc = Eaternet::Nyc.new
20
- # nyc.businesses.each { |biz| puts biz.name }
26
+ # puts nyc.businesses.map(&:name)
27
+ #
28
+ # @example Compute the average inspection score for NYC.
29
+ # # The library is optimized for memory use at the expense
30
+ # # of speed. E.g., each call to #inspections will iterate
31
+ # # through the raw CSV. So here, we first retrieve the
32
+ # # inspections into an array.
33
+ # inspections = nyc.inspections.to_a
34
+ # sum = inspections
35
+ # .map(&:score)
36
+ # .reduce(0, :+)
37
+ # count = inspections.count
38
+ #
39
+ # puts "Average inspection score: #{sum / count}"
21
40
  #
22
- # @see https://data.cityofnewyork.us/Health/DOHMH-New-York-City-Restaurant-Inspection-Results/xx67-kt59
41
+ # @example See the Instance Method Details for more examples.
42
+ #
43
+ # @see https://data.cityofnewyork.us/Health/DOHMH-New-York-City-Restaurant-Inspection-Results/xx67-kt59 NYC health scores official data, hosted on Socrata
23
44
  class Nyc < Eaternet::Lives_1_0::Adapter
24
45
  include Eaternet::Lives_1_0
25
46
  include Eaternet::Loggable
26
47
 
27
- DOMAIN = 'data.cityofnewyork.us'
28
- DATASET = 'xx67-kt59'
29
- CSV_URL = "https://#{DOMAIN}/api/views/#{DATASET}/rows.csv?accessType=DOWNLOAD"
30
-
31
- # Create an adapter for the NYC data.
48
+ # Create an NYC data-source, ready for querying.
32
49
  #
33
50
  # @example
34
51
  # nyc = Eaternet::Nyc.new
35
52
  #
36
- # @param [String] csv_path only needed for unit testing
53
+ # @param [String] csv_path for unit testing
37
54
  def initialize(csv_path: nil)
38
55
  @table_file = csv_path
39
56
  end
40
57
 
58
+ # @example Print the number of restaurants in New York.
59
+ # puts nyc.businesses.count
60
+ #
61
+ # @return [Enumerable<Business>]
41
62
  def businesses
42
63
  map_csv { |row| try_to_create_business(row) }
43
64
  .compact
44
65
  .unique
45
66
  end
46
67
 
68
+ # @example Compute the average inspection score for NYC.
69
+ #
70
+ # # The library is optimized for memory use at the expense
71
+ # # of speed. E.g., each call to #inspections will iterate
72
+ # # through the raw CSV. So here, we first retrieve the
73
+ # # inspections into an array.
74
+ # inspections = nyc.inspections.to_a
75
+ # sum = inspections
76
+ # .map(&:score)
77
+ # .reduce(0, :+)
78
+ # count = inspections.count
79
+ #
80
+ # puts "Average inspection score: #{sum / count}"
81
+ #
82
+ # @return [Enumerable<Inspection>]
47
83
  def inspections
48
84
  cache = Set.new
49
85
  map_csv do |row|
@@ -62,6 +98,11 @@ module Eaternet
62
98
  end.compact
63
99
  end
64
100
 
101
+ # @example Print the name & URL of NYC's health agency.
102
+ # puts nyc.feed_info.municipality_name
103
+ # puts nyc.feed_info.municipality_url
104
+ #
105
+ # @return [FeedInfo]
65
106
  def feed_info
66
107
  FeedInfo.new do |fi|
67
108
  fi.feed_date = Date.today
@@ -94,7 +135,7 @@ module Eaternet
94
135
  end
95
136
 
96
137
 
97
- # private
138
+ private
98
139
 
99
140
  def try_to_create_business(row)
100
141
  business(row)
@@ -114,6 +155,9 @@ module Eaternet
114
155
  nil
115
156
  end
116
157
 
158
+ public # To enable testing
159
+
160
+ # @private
117
161
  def business(row)
118
162
  address = "#{row['BUILDING']} #{row['STREET']}"
119
163
 
@@ -128,6 +172,8 @@ module Eaternet
128
172
  end
129
173
  end
130
174
 
175
+ private
176
+
131
177
  def violation(row)
132
178
  Violation.new do |v|
133
179
  v.business_id = business_id(row)
@@ -157,10 +203,6 @@ module Eaternet
157
203
  row['CAMIS']
158
204
  end
159
205
 
160
- def inspection_id(row)
161
- [row['CAMIS'], row['INSPECTION DATE']].join('-')
162
- end
163
-
164
206
  def violation_kind_id(row)
165
207
  row['VIOLATION CODE']
166
208
  end
@@ -173,6 +215,10 @@ module Eaternet
173
215
  inspection_id(row)
174
216
  end
175
217
 
218
+ def inspection_id(row)
219
+ [row['CAMIS'], row['INSPECTION DATE']].join('-')
220
+ end
221
+
176
222
  def transfat_inspection?(row)
177
223
  if row['INSPECTION TYPE']
178
224
  row['INSPECTION TYPE'].include?('Trans Fat')
@@ -204,8 +250,15 @@ module Eaternet
204
250
  end
205
251
 
206
252
  # Fastest method for downloading all data but may be non-standard
253
+ # for Socrata.
207
254
  def self.download_via_url(a_file)
208
- a_file.write(open(CSV_URL).read)
255
+ a_file.write(open(csv_url).read)
256
+ end
257
+
258
+ def csv_url
259
+ domain = 'data.cityofnewyork.us'
260
+ dataset = 'xx67-kt59'
261
+ "https://#{domain}/api/views/#{dataset}/rows.csv?accessType=DOWNLOAD"
209
262
  end
210
263
  end
211
264
  end
@@ -4,12 +4,25 @@ module Eaternet
4
4
  # and optionally {#violations}, {#feed_info}, and {#legends} to
5
5
  # implement a custom Lives 1.0 data source adapter.
6
6
  class Adapter
7
+ # @example Print the number of restaurants in SomeCity.
8
+ # some_city = Eaternet::SomeCity.new
9
+ # puts some_city.businesses.count
10
+ #
7
11
  # @required Yes
8
12
  # @return [Enumerable<Business>]
9
13
  def businesses
10
14
  fail 'Override this to return an Enumerable of Business'
11
15
  end
12
16
 
17
+ # @example Compute the average inspection score for SomeCity.
18
+ # some_city = Eaternet::SomeCity.new
19
+ # sum = some_city.inspections
20
+ # .map(&:score)
21
+ # .reduce(0, :+)
22
+ # count = some_city.inspections.count
23
+ #
24
+ # puts "Average inspection score: " + sum / count
25
+ #
13
26
  # @required Yes
14
27
  # @return [Enumerable<Inspection>]
15
28
  def inspections
@@ -22,6 +35,12 @@ module Eaternet
22
35
  fail 'Optionally override this to return an Enumerable of Violation'
23
36
  end
24
37
 
38
+ # @example Retrieve the name & URL of SomeCity's health agency.
39
+ # some_city = Eaternet::SomeCity.new
40
+ # info = some_city.feed_info
41
+ # puts info.municipality_name
42
+ # puts info.municipality_url
43
+ #
25
44
  # @required No
26
45
  # @return [FeedInfo]
27
46
  def feed_info
@@ -1,3 +1,3 @@
1
1
  module Eaternet
2
- VERSION = '0.3.10'
2
+ VERSION = '0.3.11'
3
3
  end
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.10
4
+ version: 0.3.11
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-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,14 +186,14 @@ files:
186
186
  - lib/eaternet/validated_object.rb
187
187
  - lib/eaternet/version.rb
188
188
  - lib/ext/lazy.rb
189
+ - test/eaternet/agencies/nyc_test.rb
190
+ - test/eaternet/agencies/snhd_test.rb
189
191
  - test/eaternet/eaternet_test.rb
190
192
  - test/eaternet/lives_1_0/business_test.rb
191
193
  - test/eaternet/lives_1_0/feed_info_test.rb
192
194
  - test/eaternet/lives_1_0/inspection_test.rb
193
195
  - test/eaternet/lives_1_0/legend_test.rb
194
196
  - test/eaternet/loggable_test.rb
195
- - test/eaternet/nyc_adapter_test.rb
196
- - test/eaternet/snhd_adapter_test.rb
197
197
  - test/fixtures/morris-park-bake-shop.csv
198
198
  - test/script.rb
199
199
  - test/test_helper.rb
@@ -222,14 +222,14 @@ signing_key:
222
222
  specification_version: 4
223
223
  summary: Regional adapters for restaurant health scores
224
224
  test_files:
225
+ - test/eaternet/agencies/nyc_test.rb
226
+ - test/eaternet/agencies/snhd_test.rb
225
227
  - test/eaternet/eaternet_test.rb
226
228
  - test/eaternet/lives_1_0/business_test.rb
227
229
  - test/eaternet/lives_1_0/feed_info_test.rb
228
230
  - test/eaternet/lives_1_0/inspection_test.rb
229
231
  - test/eaternet/lives_1_0/legend_test.rb
230
232
  - test/eaternet/loggable_test.rb
231
- - test/eaternet/nyc_adapter_test.rb
232
- - test/eaternet/snhd_adapter_test.rb
233
233
  - test/fixtures/morris-park-bake-shop.csv
234
234
  - test/script.rb
235
235
  - test/test_helper.rb