province-th-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"1":{"id":1,"name":"ภาคเหนือ","code":"1"},"2":{"id":2,"name":"ภาคกลาง","code":"2"},"3":{"id":3,"name":"ภาคตะวันออกเฉียงเหนือ","code":"3"},"4":{"id":4,"name":"ภาคตะวันตก","code":"4"},"5":{"id":5,"name":"ภาคตะวันออก","code":"5"},"6":{"id":6,"name":"ภาคใต้","code":"6"}}
@@ -0,0 +1 @@
1
+ {"1":{"id":1,"code":"2_10","name":"กรุงเทพมหานคร","name_en":"Bangkok","geography_id":2},"2":{"id":2,"code":"2_11","name":"สมุทรปราการ","name_en":"Samut Prakan","geography_id":2},"3":{"id":3,"code":"2_12","name":"นนทบุรี","name_en":"Nonthaburi","geography_id":2},"4":{"id":4,"code":"2_13","name":"ปทุมธานี","name_en":"Pathum Thani","geography_id":2},"5":{"id":5,"code":"2_14","name":"พระนครศรีอยุธยา","name_en":"Phra Nakhon Si Ayutthaya","geography_id":2},"6":{"id":6,"code":"2_15","name":"อ่างทอง","name_en":"Ang Thong","geography_id":2},"7":{"id":7,"code":"2_16","name":"ลพบุรี","name_en":"Loburi","geography_id":2},"8":{"id":8,"code":"2_17","name":"สิงห์บุรี","name_en":"Sing Buri","geography_id":2},"9":{"id":9,"code":"2_18","name":"ชัยนาท","name_en":"Chai Nat","geography_id":2},"10":{"id":10,"code":"2_19","name":"สระบุรี","name_en":"Saraburi","geography_id":2},"11":{"id":11,"code":"5_20","name":"ชลบุรี","name_en":"Chon Buri","geography_id":5},"12":{"id":12,"code":"5_21","name":"ระยอง","name_en":"Rayong","geography_id":5},"13":{"id":13,"code":"5_22","name":"จันทบุรี","name_en":"Chanthaburi","geography_id":5},"14":{"id":14,"code":"5_23","name":"ตราด","name_en":"Trat","geography_id":5},"15":{"id":15,"code":"5_24","name":"ฉะเชิงเทรา","name_en":"Chachoengsao","geography_id":5},"16":{"id":16,"code":"5_25","name":"ปราจีนบุรี","name_en":"Prachin Buri","geography_id":5},"17":{"id":17,"code":"2_26","name":"นครนายก","name_en":"Nakhon Nayok","geography_id":2},"18":{"id":18,"code":"5_27","name":"สระแก้ว","name_en":"Sa Kaeo","geography_id":5},"19":{"id":19,"code":"3_30","name":"นครราชสีมา","name_en":"Nakhon Ratchasima","geography_id":3},"20":{"id":20,"code":"3_31","name":"บุรีรัมย์","name_en":"Buri Ram","geography_id":3},"21":{"id":21,"code":"3_32","name":"สุรินทร์","name_en":"Surin","geography_id":3},"22":{"id":22,"code":"3_33","name":"ศรีสะเกษ","name_en":"Si Sa Ket","geography_id":3},"23":{"id":23,"code":"3_34","name":"อุบลราชธานี","name_en":"Ubon Ratchathani","geography_id":3},"24":{"id":24,"code":"3_35","name":"ยโสธร","name_en":"Yasothon","geography_id":3},"25":{"id":25,"code":"3_36","name":"ชัยภูมิ","name_en":"Chaiyaphum","geography_id":3},"26":{"id":26,"code":"3_37","name":"อำนาจเจริญ","name_en":"Amnat Charoen","geography_id":3},"27":{"id":27,"code":"3_39","name":"หนองบัวลำภู","name_en":"Nong Bua Lam Phu","geography_id":3},"28":{"id":28,"code":"3_40","name":"ขอนแก่น","name_en":"Khon Kaen","geography_id":3},"29":{"id":29,"code":"3_41","name":"อุดรธานี","name_en":"Udon Thani","geography_id":3},"30":{"id":30,"code":"3_42","name":"เลย","name_en":"Loei","geography_id":3},"31":{"id":31,"code":"3_43","name":"หนองคาย","name_en":"Nong Khai","geography_id":3},"32":{"id":32,"code":"3_44","name":"มหาสารคาม","name_en":"Maha Sarakham","geography_id":3},"33":{"id":33,"code":"3_45","name":"ร้อยเอ็ด","name_en":"Roi Et","geography_id":3},"34":{"id":34,"code":"3_46","name":"กาฬสินธุ์","name_en":"Kalasin","geography_id":3},"35":{"id":35,"code":"3_47","name":"สกลนคร","name_en":"Sakon Nakhon","geography_id":3},"36":{"id":36,"code":"3_48","name":"นครพนม","name_en":"Nakhon Phanom","geography_id":3},"37":{"id":37,"code":"3_49","name":"มุกดาหาร","name_en":"Mukdahan","geography_id":3},"38":{"id":38,"code":"1_50","name":"เชียงใหม่","name_en":"Chiang Mai","geography_id":1},"39":{"id":39,"code":"1_51","name":"ลำพูน","name_en":"Lamphun","geography_id":1},"40":{"id":40,"code":"1_52","name":"ลำปาง","name_en":"Lampang","geography_id":1},"41":{"id":41,"code":"1_53","name":"อุตรดิตถ์","name_en":"Uttaradit","geography_id":1},"42":{"id":42,"code":"1_54","name":"แพร่","name_en":"Phrae","geography_id":1},"43":{"id":43,"code":"1_55","name":"น่าน","name_en":"Nan","geography_id":1},"44":{"id":44,"code":"1_56","name":"พะเยา","name_en":"Phayao","geography_id":1},"45":{"id":45,"code":"1_57","name":"เชียงราย","name_en":"Chiang Rai","geography_id":1},"46":{"id":46,"code":"1_58","name":"แม่ฮ่องสอน","name_en":"Mae Hong Son","geography_id":1},"47":{"id":47,"code":"2_60","name":"นครสวรรค์","name_en":"Nakhon Sawan","geography_id":2},"48":{"id":48,"code":"2_61","name":"อุทัยธานี","name_en":"Uthai Thani","geography_id":2},"49":{"id":49,"code":"2_62","name":"กำแพงเพชร","name_en":"Kamphaeng Phet","geography_id":2},"50":{"id":50,"code":"4_63","name":"ตาก","name_en":"Tak","geography_id":4},"51":{"id":51,"code":"2_64","name":"สุโขทัย","name_en":"Sukhothai","geography_id":2},"52":{"id":52,"code":"2_65","name":"พิษณุโลก","name_en":"Phitsanulok","geography_id":2},"53":{"id":53,"code":"2_66","name":"พิจิตร","name_en":"Phichit","geography_id":2},"54":{"id":54,"code":"2_67","name":"เพชรบูรณ์","name_en":"Phetchabun","geography_id":2},"55":{"id":55,"code":"4_70","name":"ราชบุรี","name_en":"Ratchaburi","geography_id":4},"56":{"id":56,"code":"4_71","name":"กาญจนบุรี","name_en":"Kanchanaburi","geography_id":4},"57":{"id":57,"code":"2_72","name":"สุพรรณบุรี","name_en":"Suphan Buri","geography_id":2},"58":{"id":58,"code":"2_73","name":"นครปฐม","name_en":"Nakhon Pathom","geography_id":2},"59":{"id":59,"code":"2_74","name":"สมุทรสาคร","name_en":"Samut Sakhon","geography_id":2},"60":{"id":60,"code":"2_75","name":"สมุทรสงคราม","name_en":"Samut Songkhram","geography_id":2},"61":{"id":61,"code":"4_76","name":"เพชรบุรี","name_en":"Phetchaburi","geography_id":4},"62":{"id":62,"code":"4_77","name":"ประจวบคีรีขันธ์","name_en":"Prachuap Khiri Khan","geography_id":4},"63":{"id":63,"code":"6_80","name":"นครศรีธรรมราช","name_en":"Nakhon Si Thammarat","geography_id":6},"64":{"id":64,"code":"6_81","name":"กระบี่","name_en":"Krabi","geography_id":6},"65":{"id":65,"code":"6_82","name":"พังงา","name_en":"Phangnga","geography_id":6},"66":{"id":66,"code":"6_83","name":"ภูเก็ต","name_en":"Phuket","geography_id":6},"67":{"id":67,"code":"6_84","name":"สุราษฎร์ธานี","name_en":"Surat Thani","geography_id":6},"68":{"id":68,"code":"6_85","name":"ระนอง","name_en":"Ranong","geography_id":6},"69":{"id":69,"code":"6_86","name":"ชุมพร","name_en":"Chumphon","geography_id":6},"70":{"id":70,"code":"6_90","name":"สงขลา","name_en":"Songkhla","geography_id":6},"71":{"id":71,"code":"6_91","name":"สตูล","name_en":"Satun","geography_id":6},"72":{"id":72,"code":"6_92","name":"ตรัง","name_en":"Trang","geography_id":6},"73":{"id":73,"code":"6_93","name":"พัทลุง","name_en":"Phatthalung","geography_id":6},"74":{"id":74,"code":"6_94","name":"ปัตตานี","name_en":"Pattani","geography_id":6},"75":{"id":75,"code":"6_95","name":"ยะลา","name_en":"Yala","geography_id":6},"76":{"id":76,"code":"6_96","name":"นราธิวาส","name_en":"Narathiwat","geography_id":6},"77":{"id":77,"code":"3_97","name":"บึงกาฬ","name_en":"buogkan","geography_id":3}}
data/lib/th/amphur.rb ADDED
@@ -0,0 +1,52 @@
1
+ module Th
2
+ class Amphur
3
+ @@data ||= JSON.parse(File.read("lib/data/amphur.json"))
4
+ @@geography_id_to_data = @@data.values.group_by{|x| x["geography_id"]}
5
+ @@province_id_to_data = @@data.values.group_by{|x| x["province_id"]}
6
+
7
+ def self.data
8
+ @@data
9
+ end
10
+
11
+ def self.all
12
+ @@data.values
13
+ end
14
+
15
+ def self.find(id)
16
+ json = @@data[id.to_s]
17
+ return self.new(@@data[id.to_s]) if !json.nil?
18
+ nil
19
+ end
20
+
21
+ def initialize(json)
22
+ @json = json
23
+ end
24
+
25
+ def as_json
26
+ @json
27
+ end
28
+
29
+ def geography
30
+ Th::Geography.find(@json["geography_id"])
31
+ end
32
+
33
+ def province
34
+ Th::Province.find(@json["province_id"])
35
+ end
36
+
37
+ def districts
38
+ Th::District.districts_with_amphur_id(@json["id"])
39
+ end
40
+
41
+ def self.amphurs_with_geography_id(geography_id)
42
+ arr = @@geography_id_to_data[geography_id]
43
+ arr.map{|a| self.new(a)}
44
+ end
45
+
46
+ def self.amphurs_with_province_id(province_id)
47
+ arr = @@province_id_to_data[province_id]
48
+ arr.map{|a| self.new(a)}
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,57 @@
1
+ module Th
2
+ class District
3
+ @@data ||= JSON.parse(File.read("lib/data/district.json"))
4
+ @@geography_id_to_data = @@data.values.group_by{|x| x["geography_id"]}
5
+ @@province_id_to_data = @@data.values.group_by{|x| x["province_id"]}
6
+ @@amphur_id_to_data = @@data.values.group_by{|x| x["amphur_id"]}
7
+
8
+ def self.data
9
+ @@data
10
+ end
11
+
12
+ def self.all
13
+ @@data.values
14
+ end
15
+
16
+ def self.find(id)
17
+ json = @@data[id.to_s]
18
+ return self.new(@@data[id.to_s]) if !json.nil?
19
+ nil
20
+ end
21
+
22
+ def initialize(json)
23
+ @json = json
24
+ end
25
+
26
+ def as_json
27
+ @json
28
+ end
29
+
30
+ def geography
31
+ Th::Geography.find(@json["geography_id"])
32
+ end
33
+
34
+ def province
35
+ Th::Province.find(@json["province_id"])
36
+ end
37
+
38
+ def amphur
39
+ Th::Amphur.find(@json["amphur_id"])
40
+ end
41
+
42
+ def self.districts_with_geography_id(geography_id)
43
+ arr = @@geography_id_to_data[geography_id]
44
+ arr.map{|a| self.new(a)}
45
+ end
46
+
47
+ def self.districts_with_province_id(province_id)
48
+ arr = @@province_id_to_data[province_id]
49
+ arr.map{|a| self.new(a)}
50
+ end
51
+
52
+ def self.districts_with_amphur_id(amphur_id)
53
+ arr = @@amphur_id_to_data[amphur_id]
54
+ arr.map{|a| self.new(a)}
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ module Th
2
+ class Geography
3
+
4
+ @@data ||= JSON.parse(File.read("lib/data/geography.json"))
5
+
6
+ def self.data
7
+ @@data
8
+ end
9
+
10
+ def self.all
11
+ @@data.values
12
+ end
13
+
14
+ def self.find(id)
15
+ json = @@data[id.to_s]
16
+ return self.new(@@data[id.to_s]) if !json.nil?
17
+ nil
18
+ end
19
+
20
+ def initialize(json)
21
+ @json = json
22
+ end
23
+
24
+ def as_json
25
+ @json
26
+ end
27
+
28
+ def provinces
29
+ Th::Province.provinces_with_geography_id(@json["id"])
30
+ end
31
+
32
+ def amphurs
33
+ Th::Amphur.amphur_with_geography_id(@json["id"])
34
+ end
35
+
36
+ def districts
37
+ Th::District.districts_with_geography_id(@json["id"])
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ module Th
2
+ class Province
3
+
4
+ @@data ||= JSON.parse(File.read("lib/data/province.json"))
5
+ @@geography_id_to_data = @@data.values.group_by{|x| x["geography_id"]}
6
+
7
+ def self.data
8
+ @@data
9
+ end
10
+
11
+ def self.all
12
+ @@data.values
13
+ end
14
+
15
+ def self.find(id)
16
+ json = @@data[id.to_s]
17
+ return self.new(@@data[id.to_s]) if !json.nil?
18
+ nil
19
+ end
20
+
21
+ def initialize(json)
22
+ @json = json
23
+ end
24
+
25
+ def as_json
26
+ @json
27
+ end
28
+
29
+ def geography
30
+ Th::Geography.find(@json["geography_id"])
31
+ end
32
+
33
+ def amphurs
34
+ Th::Amphur.amphurs_with_province_id(@json["id"])
35
+ end
36
+
37
+ def districts
38
+ Th::District.districts_with_province_id(@json["id"])
39
+ end
40
+
41
+ def self.provinces_with_geography_id(geography_id)
42
+ arr = @@geography_id_to_data[geography_id]
43
+ arr.map{|a| self.new(a)}
44
+ end
45
+
46
+ end
47
+ end
data/lib/th.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "version"
2
+ require "json"
3
+ require "th/geography"
4
+ require "th/province"
5
+ require "th/amphur"
6
+ require "th/district"
7
+
8
+ module Th
9
+ # Your code goes here...
10
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Th
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "province-th-ruby"
8
+ spec.version = Th::VERSION
9
+ spec.authors = ["SaKKo Sama"]
10
+ spec.email = ["saklism@gmail.com"]
11
+
12
+ spec.summary = "none"
13
+ spec.description = "none"
14
+ spec.homepage = "https://github.com/sakko/province-th-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = spec.homepage
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "minitest", "~> 5.0"
42
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: province-th-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SaKKo Sama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: none
56
+ email:
57
+ - saklism@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/data/amphur.json
73
+ - lib/data/district.json
74
+ - lib/data/geography.json
75
+ - lib/data/province.json
76
+ - lib/th.rb
77
+ - lib/th/amphur.rb
78
+ - lib/th/district.rb
79
+ - lib/th/geography.rb
80
+ - lib/th/province.rb
81
+ - lib/version.rb
82
+ - province-th-ruby.gemspec
83
+ homepage: https://github.com/sakko/province-th-ruby
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ homepage_uri: https://github.com/sakko/province-th-ruby
88
+ source_code_uri: https://github.com/sakko/province-th-ruby
89
+ changelog_uri: https://github.com/sakko/province-th-ruby
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.7.8
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: none
110
+ test_files: []