Class: ThProvince::Amphur

Inherits:
Object
  • Object
show all
Defined in:
lib/th_province/amphur.rb

Constant Summary collapse

@@geography_id_to_data =
@@data.values.group_by{|x| x["geography_id"]}
@@province_id_to_data =
@@data.values.group_by{|x| x["province_id"]}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Amphur

Returns a new instance of Amphur.



21
22
23
# File 'lib/th_province/amphur.rb', line 21

def initialize(json)
  @json = json
end

Class Method Details

.allObject



11
12
13
# File 'lib/th_province/amphur.rb', line 11

def self.all
  @@data.values
end

.amphurs_with_geography_id(geography_id) ⇒ Object



41
42
43
44
# File 'lib/th_province/amphur.rb', line 41

def self.amphurs_with_geography_id(geography_id)
  arr = @@geography_id_to_data[geography_id]
  arr.map{|a| self.new(a)}
end

.amphurs_with_province_id(province_id) ⇒ Object



46
47
48
49
# File 'lib/th_province/amphur.rb', line 46

def self.amphurs_with_province_id(province_id)
  arr = @@province_id_to_data[province_id]
  arr.map{|a| self.new(a)}
end

.dataObject



7
8
9
# File 'lib/th_province/amphur.rb', line 7

def self.data
  @@data
end

.find(id) ⇒ Object



15
16
17
18
19
# File 'lib/th_province/amphur.rb', line 15

def self.find(id)
  json = @@data[id.to_s]
  return self.new(@@data[id.to_s]) if !json.nil?
  nil
end

Instance Method Details

#as_jsonObject



25
26
27
# File 'lib/th_province/amphur.rb', line 25

def as_json
  @json
end

#districtsObject



37
38
39
# File 'lib/th_province/amphur.rb', line 37

def districts
  ThProvince::District.districts_with_amphur_id(@json["id"])
end

#geographyObject



29
30
31
# File 'lib/th_province/amphur.rb', line 29

def geography
  ThProvince::Geography.find(@json["geography_id"])
end

#provinceObject



33
34
35
# File 'lib/th_province/amphur.rb', line 33

def province
  ThProvince::Province.find(@json["province_id"])
end