class Eaternet::Agencies::SnhdPrototype
An adapter for the Southern Nevada Health District (Las Vegas).
@note This is a work in progress. @private @see southernnevadahealthdistrict.org/restaurants/inspect-downloads.php
The SNHD Developer information page
@see Eaternet::Prototype
Framework module
Public Instance Methods
businesses()
click to toggle source
(see Eaternet::Prototype::AbstractAdapter#businesses
)
# File lib/eaternet/agencies/snhd_prototype.rb, line 19 def businesses lazy_csv_map('restaurant_establishments.csv') do |row| Eaternet::Prototype::BusinessData.new( orig_key: row['permit_number'], name: row['restaurant_name'], address: row['address'], city: row['city_name'], zipcode: row['zip_code'] ) end end
inspections()
click to toggle source
(see Eaternet::Prototype::AbstractAdapter#inspections
)
# File lib/eaternet/agencies/snhd_prototype.rb, line 32 def inspections lazy_csv_map('restaurant_inspections.csv') do |row| violations = if row['violations'] row['violations'].split(',') else [] end Eaternet::Prototype::InspectionData.new( orig_key: row['serial_number'], business_orig_key: row['permit_number'], score: row['inspection_grade'], demerits: row['inspection_demerits'], date: row['inspection_date'], violations: violations ) end end
violation_kinds()
click to toggle source
@return [Enumerable<ViolationKindData>] @todo Add to AbstractAdapter
# File lib/eaternet/agencies/snhd_prototype.rb, line 69 def violation_kinds lazy_csv_map('restaurant_violations.csv') do |row| Eaternet::Prototype::ViolationKindData.new( orig_key: row['violation_id'], code: row['violation_code'], demerits: row['violation_demerits'], description: row['violation_description'] ) end end
violations()
click to toggle source
(see Eaternet::Prototype::AbstractAdapter#violations
)
# File lib/eaternet/agencies/snhd_prototype.rb, line 51 def violations result = [] inspections.each do |i| i.violations.each do |v| result << Eaternet::Prototype::ViolationData.new( inspection_id: i.orig_key, violation_kind_id: v, orig_key: 'n/a' ) end end result end
Private Instance Methods
csv_reader(path:)
click to toggle source
# File lib/eaternet/agencies/snhd_prototype.rb, line 90 def csv_reader(path:) file = open(path, encoding: 'utf-8') CSV.new( file, headers: true, col_sep: SnhdConfig::COLUMN_SEPARATOR, quote_char: SnhdConfig::QUOTE_CHARACTER ) end
csv_rows(filename)
click to toggle source
# File lib/eaternet/agencies/snhd_prototype.rb, line 86 def csv_rows(filename) csv_reader path: File.join(zip_dir, filename) end
lazy_csv_map(filename) { |row| ... }
click to toggle source
# File lib/eaternet/agencies/snhd_prototype.rb, line 82 def lazy_csv_map(filename) csv_rows(filename).lazy.map { |row| yield(row) } end
zip_dir()
click to toggle source
# File lib/eaternet/agencies/snhd_prototype.rb, line 100 def zip_dir Util.download_and_extract_zipfile(SnhdConfig::DOWNLOAD_URL) end