class Eaternet::Agencies::Sf
Public Instance Methods
adapter_name()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 37 def adapter_name 'SF' end
businesses()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 15 def businesses convert csv: 'businesses.csv', to_type: :business end
feed_info()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 27 def feed_info Eaternet::Lives_1_0::FeedInfo.new do |fi| fi.feed_date = Date.today fi.feed_version = '1.0' fi.municipality_name = 'San Francisco' fi.municipality_url = 'https://www.sfdph.org/dph/EH/Food/Score/default.asp' fi.contact_email = 'contact@sfdph.org' end end
inspections()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 19 def inspections convert csv: 'inspections.csv', to_type: :inspection end
violations()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 23 def violations convert csv: 'violations.csv', to_type: :violation end
zip_file_url()
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 41 def zip_file_url 'https://extxfer.sfdph.org/food/SFBusinesses.zip' end
Private Instance Methods
business(csv_row)
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 47 def business(csv_row) Eaternet::Lives_1_0::Business.new do |b| csv_row.headers.each do |header| b.send("#{header.downcase}=", csv_row[header]) end end end
csv_reader(path:)
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 81 def csv_reader(path:) CSV.new(open(path, encoding: 'ISO-8859-1'), headers: true) end
fix(description:)
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 75 def fix(description:) # Remove bracketed violation facts, non-conforming to LIVES return description unless description =~ /^([^\[]+)/ $1.strip end
inspection(csv_row)
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 55 def inspection(csv_row) Eaternet::Lives_1_0::Inspection.new do |b| csv_row.headers.each do |header| b.send("#{header.downcase}=", csv_row[header]) b.date = Date.parse(csv_row['date']) b.score = csv_row['score'].to_i end end end
violation(csv_row)
click to toggle source
# File lib/eaternet/agencies/sf.rb, line 65 def violation(csv_row) Eaternet::Lives_1_0::Violation.new do |b| csv_row.headers.each do |header| b.send("#{header.downcase}=", csv_row[header]) b.date = Date.parse(csv_row['date']) b.description = fix(description: csv_row['description']) end end end