class Eaternet::Agencies::Lives2

Public Class Methods

new(feed_url:, municipality_name:, municipality_url:, contact_email:) click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 15
def initialize(feed_url:, municipality_name:, municipality_url:, contact_email:)
  @feed_url = feed_url
  @municipality_name = municipality_name
  @municipality_url = municipality_url
  @contact_email = contact_email
end

Public Instance Methods

adapter_name() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 44
def adapter_name
  @municipality_name
end
businesses() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 22
def businesses
  convert csv: 'businesses.csv', to_type: :business
end
feed_info() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 34
def feed_info
  Eaternet::Lives_1_0::FeedInfo.new do |fi|
    fi.feed_date =         Date.today
    fi.feed_version =      '2.0'
    fi.municipality_name = @municipality_name
    fi.municipality_url =  @municipality_url
    fi.contact_email =     @contact_email
  end
end
inspections() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 26
def inspections
  convert csv: 'inspections.csv', to_type: :inspection
end
violations() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 30
def violations
  convert csv: 'violations.csv', to_type: :violation
end
zip_file_url() click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 48
def zip_file_url
  @feed_url
end

Private Instance Methods

business(csv_row) click to toggle source
# File lib/eaternet/agencies/lives2.rb, line 54
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/lives2.rb, line 88
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/lives2.rb, line 82
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/lives2.rb, line 62
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/lives2.rb, line 72
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