Class: ThProvince::Amphur
- Inherits:
-
Object
- Object
- ThProvince::Amphur
- 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
- .all ⇒ Object
- .amphurs_with_geography_id(geography_id) ⇒ Object
- .amphurs_with_province_id(province_id) ⇒ Object
- .data ⇒ Object
- .find(id) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
- #districts ⇒ Object
- #geography ⇒ Object
-
#initialize(json) ⇒ Amphur
constructor
A new instance of Amphur.
- #province ⇒ Object
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
.all ⇒ Object
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 |
.data ⇒ Object
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_json ⇒ Object
25 26 27 |
# File 'lib/th_province/amphur.rb', line 25 def as_json @json end |
#districts ⇒ Object
37 38 39 |
# File 'lib/th_province/amphur.rb', line 37 def districts ThProvince::District.districts_with_amphur_id(@json["id"]) end |
#geography ⇒ Object
29 30 31 |
# File 'lib/th_province/amphur.rb', line 29 def geography ThProvince::Geography.find(@json["geography_id"]) end |
#province ⇒ Object
33 34 35 |
# File 'lib/th_province/amphur.rb', line 33 def province ThProvince::Province.find(@json["province_id"]) end |