Class: Eaternet::Agencies::Nyc

Inherits:
Lives_1_0::Adapter show all
Includes:
Lives_1_0, Loggable
Defined in:
lib/eaternet/agencies/nyc.rb

Overview

TODO:

This is a somewhat long namespace. Can this be improved?

A LIVES 1.0 data source for New York City.

Example: print all the restaurant names in New York City.

```ruby
require 'eaternet'

nyc = Eaternet::Nyc.new
nyc.businesses.each { |biz| puts biz.name }
```

Constant Summary collapse

DOMAIN =
'data.cityofnewyork.us'
DATASET =
'xx67-kt59'
CSV_URL =
"https://#{DOMAIN}/api/views/#{DATASET}/rows.csv?accessType=DOWNLOAD"

Instance Method Summary collapse

Methods included from Loggable

#create_logger, #logger

Constructor Details

#initialize(csv_path: nil) ⇒ Nyc

Create an NYC Adapter.

Parameters:

  • csv_path

    for unit testing


40
41
42
# File 'lib/eaternet/agencies/nyc.rb', line 40

def initialize(csv_path: nil)
  @table_file = csv_path
end

Instance Method Details

#businessesObject


44
45
46
47
48
# File 'lib/eaternet/agencies/nyc.rb', line 44

def businesses
  map_csv { |row| try_to_create_business(row) }
  .compact
  .unique
end

#feed_infoObject


68
69
70
71
72
73
74
75
# File 'lib/eaternet/agencies/nyc.rb', line 68

def feed_info
  FeedInfo.new do |fi|
    fi.feed_date = Date.today
    fi.feed_version = '1.0'
    fi.municipality_name = 'New York City'
    fi.municipality_url = 'http://www.nyc.gov/html/doh/html/services/restaurant-inspection.shtml'
  end
end

#inspectionsObject


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/eaternet/agencies/nyc.rb', line 50

def inspections
  cache = Set.new
  map_csv do |row|
    if inspection_should_be_skipped?(cache, row)
      nil
    else
      save_to_inspection_cache(cache, row)
      try_to_create_inspection(row)
    end
  end.compact
end

#legendsObject


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/eaternet/agencies/nyc.rb', line 77

def legends
  LegendGroup.new do |lg|
    lg.legends = [
      Legend.new do |l|
        l.minimum_score = 87
        l.maximum_score = 100
        l.description =   'A'
      end,
      Legend.new do |l|
        l.minimum_score = 73
        l.maximum_score = 86
        l.description =   'B'
      end,
      Legend.new do |l|
        l.minimum_score = 0
        l.maximum_score = 72
        l.description =   'C'
      end
    ]
  end
end

#violationsObject


62
63
64
65
66
# File 'lib/eaternet/agencies/nyc.rb', line 62

def violations
  map_csv do |row|
    violation_should_be_skipped?(row) ? nil : violation(row)
  end.compact
end