Class: Iarea::Prefecture

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

Overview

Prefecture

Constant Summary collapse

@@prefectures =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject

All prefectures



29
30
31
# File 'lib/iarea/prefecture.rb', line 29

def all
  DB['prefecture_ids'].map{ |id| find(id) }
end

.find(id) ⇒ Object

Find a prefecture by id



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

def find(id)
  if prefecture = @@prefectures[id.to_i]
    prefecture
  elsif prefecture_data = DB['prefecture'][id.to_i]
    @@prefectures[id.to_i] ||= new(prefecture_data)
  else
    nil
  end
end

Instance Method Details

#areasObject

Areas in the prefecture



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

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

#zoneObject

Zone of the prefecture



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

def zone
  Zone.find(self.zone_id)
end