class Eaternet::Agencies::Austin

@see data.austintexas.gov/dataset/Restaurant-Inspection-Scores/ecmv-9xxi

Public Class Methods

csv_url() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 109
def self.csv_url
  Eaternet::Socrata.csv_url domain: 'data.austintexas.gov', dataset: 'ecmv-9xxi'
end
download_via_url() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 105
def self.download_via_url
  Eaternet::Util.download_and_cache(source: csv_url, dest: Tempfile.new('austin'))
end
new(csv_path: nil) click to toggle source

Create an Austin data-source, ready for querying.

@example

austin = Eaternet::Austin.new

@param [String] csv_path for unit testing

# File lib/eaternet/agencies/austin.rb, line 19
def initialize(csv_path: nil)
  @table_file = csv_path
end

Public Instance Methods

adapter_name() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 113
def adapter_name
  'Austin'
end
business(row) click to toggle source
# File lib/eaternet/agencies/austin.rb, line 71
def business(row)
  Eaternet::Lives_1_0::Business.new do |b|
    fail ArgumentError, 'No address found' if row['Address'].nil?

    # Address is a multi-line, multi-value cell
    address_lines = row['Address'].split("\n")
    if address_lines.size != 3
      fail ArgumentError,
           "Address doesn't have three lines: {row['Address']}"
    end

    address = address_lines.first
    city    = address_lines[1].split(',').first
    address_lines[2] =~ /^\(([^,]+), (.+)\)$/
    lat = Regexp.last_match(1)
    lon = Regexp.last_match(2)

    b.business_id = row['Facility ID']
    b.name =        row['Restaurant Name']
    b.address =     address
    b.city =        city
    b.postal_code = row['Zip Code']
    b.state       = 'TX'
    b.latitude    = lat
    b.longitude   = lon
  end
end
businesses() click to toggle source

@example Print the number of restaurants in the city.

puts austin.businesses.count

@return [Enumerable<Business>]

# File lib/eaternet/agencies/austin.rb, line 28
def businesses
  map_csv { |row| try_to_create(:business, from_csv_row: row) }
    .uniq
    .compact
end
feed_info() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 51
def feed_info
  Eaternet::Lives_1_0::FeedInfo.new do |fi|
    fi.feed_date = Date.today
    fi.feed_version = '1.0'
    fi.municipality_name = 'Austin'
    fi.municipality_url = 'http://www.austintexas.gov/department/health'
  end
end
inspection(row) click to toggle source
# File lib/eaternet/agencies/austin.rb, line 62
def inspection(row)
  Eaternet::Lives_1_0::Inspection.new do |i|
    i.business_id = row['Facility ID']
    i.date =        Date.strptime(row['Inspection Date'], '%m/%d/%Y')
    i.score =       row['Score'].to_i
  end
end
inspections() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 35
def inspections
  map_csv { |row| try_to_create(:inspection, from_csv_row: row) }
    .compact
end
legends() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 46
def legends
  fail Eaternet::UnsupportedError, 'Austin does not assign letter grades'
end
table_file() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 101
def table_file
  Austin.download_via_url
end
violations() click to toggle source
# File lib/eaternet/agencies/austin.rb, line 41
def violations
  fail Eaternet::UnsupportedError, "Austin doesn't publish violation data"
end