Class: Iarea::Area
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Iarea::Area
- Defined in:
- lib/iarea/area.rb
Overview
Area
Constant Summary collapse
- @@areas =
{}
Class Method Summary collapse
-
.find(areacode) ⇒ Object
Find area by
areacode
. -
.find_by_lat_lng(lat, lng) ⇒ Object
Find area by latitude and longitude in degrees.
Instance Method Summary collapse
-
#neighbors ⇒ Object
Neighbor areas of the area.
-
#prefecture ⇒ Object
Prefecture of the area.
-
#zone ⇒ Object
Zone of the area.
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.(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
#neighbors ⇒ Object
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 |
#prefecture ⇒ Object
Prefecture of the area
7 8 9 |
# File 'lib/iarea/area.rb', line 7 def prefecture Prefecture.find(self.prefecture_id) end |