class Eaternet::Agencies::Snhd

Public Class Methods

new() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 14
def initialize
  @prototype = Eaternet::Agencies::SnhdPrototype.new
end

Public Instance Methods

_violations() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 71
def _violations
  violation_kinds = {}
  @prototype.violation_kinds.each do |vk|
    violation_kinds[vk.orig_key] = vk
  end

  result = []

  @prototype.inspections.each do |proto_inspection|
    proto_inspection.violations.each do |kind_id|
      begin
        result << Eaternet::Lives_1_0::Violation.new do |v|
          v.business_id = proto_inspection.business_orig_key
          v.date =        Date.parse(proto_inspection.date)
          v.code =        violation_kinds[kind_id].code
          v.description = violation_kinds[kind_id].description
        end
      rescue StandardError => e
        logger.debug "Error creating violation kind #{kind_id} for inspection #{proto_inspection.orig_key}: #{e}"
      end
    end
  end
  result.compact
end
adapter_name() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 18
def adapter_name
  'SNHD'
end
business(proto) click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 34
def business(proto)
  Eaternet::Lives_1_0::Business.new do |b|
    b.business_id = proto.orig_key
    b.name =    proto.name
    b.address = proto.address
    b.city =    proto.city
    b.postal_code = proto.zipcode
    b.state = 'NV'
  end
end
businesses() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 22
def businesses
  @prototype.businesses
            .map { |proto| try_to_create(:business, from_csv_row: proto) }
            .compact
end
feed_info() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 57
def feed_info
  Eaternet::Lives_1_0::FeedInfo.new do |fi|
    fi.feed_date = Date.today
    fi.feed_version = '1.0'
    fi.municipality_name = 'Southern Nevada'
    fi.municipality_url = 'http://southernnevadahealthdistrict.org/restaurants/index.php'
    fi.contact_email = 'environmentalhealth@snhdmail.org'
  end
end
inspection(proto) click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 45
def inspection(proto)
  Eaternet::Lives_1_0::Inspection.new do |i|
    i.business_id = proto.business_orig_key
    i.score = proto.demerits.nil? ? nil : 100 - proto.demerits.to_i
    i.date = Date.parse(proto.date)
  end
end
inspections() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 28
def inspections
  @prototype.inspections
            .map { |proto| try_to_create(:inspection, from_csv_row: proto) }
            .compact
end
legends() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 67
def legends
  []
end
violations() click to toggle source
# File lib/eaternet/agencies/snhd.rb, line 53
def violations
  @violations ||= _violations
end