Class: Eaternet::Agencies::Austin
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
#convert, #csv_map, #csv_rows, #map_csv, #try_to_create, #zip_dir, #zip_file_url
Methods included from Loggable
#logger
Constructor Details
#initialize(csv_path: nil) ⇒ Austin
Create an Austin data-source, ready for querying.
18
19
20
|
# File 'lib/eaternet/agencies/austin.rb', line 18
def initialize(csv_path: nil)
@table_file = csv_path
end
|
Class Method Details
.csv_url ⇒ Object
102
103
104
|
# File 'lib/eaternet/agencies/austin.rb', line 102
def self.csv_url
Eaternet::Socrata.csv_url domain: 'data.austintexas.gov', dataset: 'ecmv-9xxi'
end
|
.download_via_url ⇒ Object
98
99
100
|
# File 'lib/eaternet/agencies/austin.rb', line 98
def self.download_via_url
Eaternet::Util.download_and_cache(source: csv_url, dest: Tempfile.new('austin'))
end
|
Instance Method Details
#adapter_name ⇒ Object
106
107
108
|
# File 'lib/eaternet/agencies/austin.rb', line 106
def adapter_name
'Austin'
end
|
#business(row) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/eaternet/agencies/austin.rb', line 64
def business(row)
Eaternet::Lives_1_0::Business.new do |b|
fail ArgumentError, 'No address found' if row['Address'].nil?
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 ⇒ Enumerable<Business>
26
27
28
29
30
|
# File 'lib/eaternet/agencies/austin.rb', line 26
def businesses
map_csv { |row| try_to_create(:business, from_csv_row: row) }
.uniq
.compact
end
|
#feed_info ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/eaternet/agencies/austin.rb', line 45
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) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/eaternet/agencies/austin.rb', line 56
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 ⇒ Object
32
33
34
35
|
# File 'lib/eaternet/agencies/austin.rb', line 32
def inspections
map_csv { |row| try_to_create(:inspection, from_csv_row: row) }
.compact
end
|
#legends ⇒ Object
41
42
43
|
# File 'lib/eaternet/agencies/austin.rb', line 41
def legends
fail Eaternet::UnsupportedError, 'Austin does not assign letter grades'
end
|
#table_file ⇒ Object
94
95
96
|
# File 'lib/eaternet/agencies/austin.rb', line 94
def table_file
@table_file ||= Austin.download_via_url
end
|
#violations ⇒ Object
37
38
39
|
# File 'lib/eaternet/agencies/austin.rb', line 37
def violations
fail Eaternet::UnsupportedError, "Austin doesn't publish violation data"
end
|