Class: Eaternet::Agencies::Nyc
- Inherits:
-
Lives_1_0::Adapter
- Object
- Lives_1_0::Adapter
- Eaternet::Agencies::Nyc
- Includes:
- Lives_1_0::CsvParser, Loggable
- Defined in:
- lib/eaternet/agencies/nyc.rb
Overview
A data source for New York City food service health inspections. It retrieves the latest CSV export from the official source and makes it easy to work with. See our NYC wiki page for details about the data set.
Output is produced in the LIVES 1.0 format developed by Yelp and the cities of San Francisco and New York.
The downloaded CSV is cached for twelve hours in a temporary file.
Instance Method Summary collapse
- #businesses ⇒ Enumerable<Business>
- #feed_info ⇒ FeedInfo
-
#initialize(csv_path: nil) ⇒ Nyc
constructor
Create an NYC data-source, ready for querying.
- #inspections ⇒ Enumerable<Inspection>
- #legends ⇒ Enumerable<Legend>
- #violations ⇒ Enumerable<Violation>
Methods included from Lives_1_0::CsvParser
#convert, #csv_map, #csv_rows, #map_csv, #try_to_create, #zip_dir, #zip_file_url
Methods included from Loggable
Constructor Details
#initialize(csv_path: nil) ⇒ Nyc
Create an NYC data-source, ready for querying.
59 60 61 |
# File 'lib/eaternet/agencies/nyc.rb', line 59 def initialize(csv_path: nil) @fixture_table_file = csv_path end |
Instance Method Details
#businesses ⇒ Enumerable<Business>
67 68 69 70 71 |
# File 'lib/eaternet/agencies/nyc.rb', line 67 def businesses map_csv { |row| try_to_create(:business, from_csv_row: row) } .uniq .compact end |
#feed_info ⇒ FeedInfo
104 105 106 107 108 109 110 111 112 |
# File 'lib/eaternet/agencies/nyc.rb', line 104 def feed_info # Anyone know a contact email? Eaternet::Lives_1_0::FeedInfo.new do |fi| fi.feed_date = Date.today fi.feed_version = '1.0' fi.municipality_name = 'New York City' fi.municipality_url = 'http://www.nyc.gov/html/doh/html/services/restaurant-inspection.shtml' end end |
#inspections ⇒ Enumerable<Inspection>
87 88 89 90 91 |
# File 'lib/eaternet/agencies/nyc.rb', line 87 def inspections map_csv { |row| skip_inspection?(row) ? nil : try_to_create(:inspection, from_csv_row: row) } .uniq .compact end |
#legends ⇒ Enumerable<Legend>
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/eaternet/agencies/nyc.rb', line 115 def legends Eaternet::Lives_1_0::LegendGroup.new do |lg| lg.legends = [ Eaternet::Lives_1_0::Legend.new do |l| l.minimum_score = 87 l.maximum_score = 100 l.description = 'A' end, Eaternet::Lives_1_0::Legend.new do |l| l.minimum_score = 73 l.maximum_score = 86 l.description = 'B' end, Eaternet::Lives_1_0::Legend.new do |l| l.minimum_score = 0 l.maximum_score = 72 l.description = 'C' end ] end.legends end |
#violations ⇒ Enumerable<Violation>
94 95 96 97 |
# File 'lib/eaternet/agencies/nyc.rb', line 94 def violations map_csv { |row| skip_violation?(row) ? nil : violation(row) } .compact end |