Class: Iarea::Zone

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

Constant Summary collapse

@@zones =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject

All zones



28
29
30
# File 'lib/iarea/zone.rb', line 28

def all
  DB['zone_ids'].map{|id| Zone.find id}
end

.find(id) ⇒ Object

Find a zone by id



17
18
19
20
21
22
23
24
25
# File 'lib/iarea/zone.rb', line 17

def find(id)
  if zone = @@zones[id.to_i]
    zone
  elsif zone_data = DB['zone'][id.to_i]
    @@zones[id.to_i] ||= new(zone_data)
  else
    nil
  end
end

Instance Method Details

#areasObject

Areas in the zone



11
12
13
# File 'lib/iarea/zone.rb', line 11

def areas
  self.areacodes.map {|areacode| Area.find areacode}
end

#prefecturesObject

Prefectures in the zone



6
7
8
# File 'lib/iarea/zone.rb', line 6

def prefectures
  self.prefecture_ids.map {|prefecture_id| Prefecture.find prefecture_id}
end