Class: ThProvince::Province

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Province

Returns a new instance of Province.



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

def initialize(json)
  @json = json
end

Class Method Details

.allObject



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

def self.all
  @@data.values
end

.dataObject



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

def self.data
  @@data
end

.find(id) ⇒ Object



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

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

.provinces_with_geography_id(geography_id) ⇒ Object



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

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

Instance Method Details

#amphursObject



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

def amphurs
  ThProvince::Amphur.amphurs_with_province_id(@json["id"])
end

#as_jsonObject



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

def as_json
  @json
end

#districtsObject



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

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

#geographyObject



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

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