Module: Sandy::Provider::StormCenter

Includes:
CoordinateCache
Included in:
ConEd::Report, LIPA::Report
Defined in:
lib/sandy/providers/storm_center.rb

Instance Method Summary collapse

Methods included from CoordinateCache

#cached_coordinates_for, #gps_data

Instance Method Details

#recursive_fetch_areas(report_areas, sub_select_func, parent = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sandy/providers/storm_center.rb', line 5

def recursive_fetch_areas report_areas, sub_select_func, parent=nil
  if report_areas
    arr = []
      report_areas.each do |report_area|
        begin

          latitude, longitude = cached_coordinates_for(report_area['area_name'].downcase)

          options = {
            parent: parent,
            total_customers: report_area.fetch("total_custs", 0).to_i,
            estimated_recovery_time: report_area.fetch("etr", nil),
            latitude: latitude,
            longitude: longitude,
            children: recursive_fetch_areas(sub_select_func.call(report_area), sub_select_func, report_area)
          }

          arr.push Sandy::Area.new(report_area.fetch("custs_out", 0).to_i, sanitize_name(report_area.fetch("area_name", nil)), options)
        rescue
          # FIXME: raise warning if any region is empty.
          next
        end
      end
    arr
  else
    []
  end
end

#sanitize_name(str) ⇒ Object



34
35
36
# File 'lib/sandy/providers/storm_center.rb', line 34

def sanitize_name str
  str.split(' ').map {|w| w.downcase.capitalize }.join(' ')
end