Class: Iarea::Area

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/iarea/area.rb

Overview

Area

Constant Summary collapse

@@areas =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(areacode) ⇒ Object

Find area by areacode



23
24
25
26
27
28
29
30
31
# File 'lib/iarea/area.rb', line 23

def find(areacode)
  if area = @@areas[areacode]
    area
  elsif area_data = DB['area'][areacode]
    @@areas[areacode] ||= new(area_data)
  else
    nil
  end
end

.find_by_lat_lng(lat, lng) ⇒ Object

Find area by latitude and longitude in degrees



34
35
36
37
38
39
40
41
42
# File 'lib/iarea/area.rb', line 34

def find_by_lat_lng(lat, lng)
  meshcodes = Utils.expand_meshcode(Utils.lat_lng_to_meshcode(lat, lng))
  meshcodes.each do |meshcode|
    if areacode = MESH[meshcode]
      return find(areacode)
    end
  end
  return nil
end

Instance Method Details

#neighborsObject

Neighbor areas of the area



17
18
19
# File 'lib/iarea/area.rb', line 17

def neighbors
  @table[:neighbors].map{|areacode| Area.find areacode}
end

#prefectureObject

Prefecture of the area



7
8
9
# File 'lib/iarea/area.rb', line 7

def prefecture
  Prefecture.find(self.prefecture_id)
end

#zoneObject

Zone of the area



12
13
14
# File 'lib/iarea/area.rb', line 12

def zone
  Zone.find(self.zone_id)
end