taiwan_address 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +18 -9
- data/lib/taiwan_address/config/locale/ja.yml +5 -5
- data/lib/taiwan_address/reader.rb +59 -30
- data/lib/taiwan_address/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e181093fb7e5406211ff3553f73b33811ee869bb
|
4
|
+
data.tar.gz: 2563e49414792e56ad4e32ca0b3ac47b9caa7130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ccdf9129f3c5479bfef3d682802a62db1d2509a16cb2126bcb4a54b94f1d0721564822cd26be4ad6b8fb5a938b85cbd31316cab5729358300924b76d654ff9
|
7
|
+
data.tar.gz: fd78e6805fbc8af4c886f813b987688509acd343d4d8f41b50a0001258b524add6dafcfa0ecde08b4801524ed22c1d73001671ecb9b20135a55f25643d6612f9
|
data/README.md
CHANGED
@@ -22,15 +22,24 @@ $ gem install taiwan_address
|
|
22
22
|
### Reader
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
address = TaiwanAddress::Reader.new(203, :"zh-TW")
|
26
|
+
address.zone # => "基隆市"
|
27
|
+
address.district # => "中山區"
|
28
|
+
address.address # => "基隆市 中山區"
|
29
|
+
|
30
|
+
address.locale = :en
|
31
|
+
address.zone # => "Keelung City"
|
32
|
+
address.district # => "Zhongshan District"
|
33
|
+
address.address # => "Keelung City Zhongshan District"
|
34
|
+
|
35
|
+
address.code = 815
|
36
|
+
address.address # => "Kaohsiung City Dashe District"
|
37
|
+
address.is_city? # => true
|
38
|
+
address.is_county? # => false
|
39
|
+
|
40
|
+
address.is_district? # => true
|
41
|
+
address.is_township? # => false
|
42
|
+
address.is_islands? # => false
|
34
43
|
```
|
35
44
|
|
36
45
|
## Development
|
@@ -28,7 +28,7 @@ ja:
|
|
28
28
|
zhongshan_district: '中山区'
|
29
29
|
songshan_district: '松山区'
|
30
30
|
da_an_district: '大安区'
|
31
|
-
wanhua_district: '
|
31
|
+
wanhua_district: '万華区'
|
32
32
|
xinyi_district: '信義区'
|
33
33
|
shilin_district: '士林区'
|
34
34
|
beitou_district: '北投区'
|
@@ -46,7 +46,7 @@ ja:
|
|
46
46
|
beigan_township: '北竿郷'
|
47
47
|
juguang_township: '莒光郷'
|
48
48
|
dongyin_township: '東引郷'
|
49
|
-
wanli_district: '
|
49
|
+
wanli_district: '万里区'
|
50
50
|
jinshan_district: '金山区'
|
51
51
|
banqiao_district: '板橋区'
|
52
52
|
xizhi_district: '汐止区'
|
@@ -340,11 +340,11 @@ ja:
|
|
340
340
|
linluo_township: '麟洛郷'
|
341
341
|
zhutian_township: '竹田郷'
|
342
342
|
neipu_township: '內埔郷'
|
343
|
-
wandan_township: '
|
343
|
+
wandan_township: '万丹郷'
|
344
344
|
chaozhou_township: '潮州鎮'
|
345
345
|
taiwu_township: '泰武郷'
|
346
346
|
laiyi_township: '來義郷'
|
347
|
-
wanluan_township: '
|
347
|
+
wanluan_township: '万巒郷'
|
348
348
|
kanding_township: '崁頂郷'
|
349
349
|
xinpi_township: '新埤郷'
|
350
350
|
nanzhou_township: '南州郷'
|
@@ -386,7 +386,7 @@ ja:
|
|
386
386
|
guangfu_township: '光復郷'
|
387
387
|
fengbin_township: '豐濱郷'
|
388
388
|
ruisui_township: '瑞穗郷'
|
389
|
-
wanrong_township: '
|
389
|
+
wanrong_township: '万榮郷'
|
390
390
|
yuli_township: '玉里鎮'
|
391
391
|
zhuoxi_township: '卓溪郷'
|
392
392
|
fuli_township: '富里郷'
|
@@ -1,78 +1,107 @@
|
|
1
1
|
module TaiwanAddress
|
2
2
|
class Reader
|
3
|
-
attr_accessor :locale
|
3
|
+
attr_accessor :locale, :code
|
4
4
|
|
5
5
|
def initialize(code, locale = :en)
|
6
6
|
@code = code
|
7
7
|
@locale = locale
|
8
8
|
end
|
9
9
|
|
10
|
-
def zone
|
11
|
-
|
10
|
+
def zone(locale: nil)
|
11
|
+
locale = locale || @locale
|
12
12
|
code = @code
|
13
13
|
case
|
14
14
|
when code.between?(100, 116)
|
15
|
-
I18n.t('zone.taipei_city')
|
15
|
+
I18n.t('zone.taipei_city', locale: locale)
|
16
16
|
when code.between?(200, 206)
|
17
|
-
I18n.t('zone.keelung_city')
|
17
|
+
I18n.t('zone.keelung_city', locale: locale)
|
18
18
|
when code.between?(209, 212)
|
19
|
-
I18n.t('zone.lienchiang_county')
|
19
|
+
I18n.t('zone.lienchiang_county', locale: locale)
|
20
20
|
when code.between?(207, 208)
|
21
|
-
I18n.t('zone.new_taipei_city')
|
21
|
+
I18n.t('zone.new_taipei_city', locale: locale)
|
22
22
|
when code.between?(220, 253)
|
23
|
-
I18n.t('zone.new_taipei_city')
|
23
|
+
I18n.t('zone.new_taipei_city', locale: locale)
|
24
24
|
when code.between?(260, 290)
|
25
|
-
I18n.t('zone.yilan_county')
|
25
|
+
I18n.t('zone.yilan_county', locale: locale)
|
26
26
|
when code == 300
|
27
|
-
I18n.t('zone.hsinchu_city')
|
27
|
+
I18n.t('zone.hsinchu_city', locale: locale)
|
28
28
|
when code.between?(302, 315)
|
29
|
-
I18n.t('zone.hsinchu_county')
|
29
|
+
I18n.t('zone.hsinchu_county', locale: locale)
|
30
30
|
when code.between?(320, 338)
|
31
|
-
I18n.t('zone.taoyuan_city')
|
31
|
+
I18n.t('zone.taoyuan_city', locale: locale)
|
32
32
|
when code.between?(350, 369)
|
33
|
-
I18n.t('zone.miaoli_county')
|
33
|
+
I18n.t('zone.miaoli_county', locale: locale)
|
34
34
|
when code.between?(400, 439)
|
35
|
-
I18n.t('zone.taichung_city')
|
35
|
+
I18n.t('zone.taichung_city', locale: locale)
|
36
36
|
when code.between?(500, 530)
|
37
|
-
I18n.t('zone.changhua_county')
|
37
|
+
I18n.t('zone.changhua_county', locale: locale)
|
38
38
|
when code.between?(540, 558)
|
39
|
-
I18n.t('zone.nantou_county')
|
39
|
+
I18n.t('zone.nantou_county', locale: locale)
|
40
40
|
when code == 600
|
41
|
-
I18n.t('zone.chiayi_city')
|
41
|
+
I18n.t('zone.chiayi_city', locale: locale)
|
42
42
|
when code.between?(602, 625)
|
43
|
-
I18n.t('zone.chiayi_county')
|
43
|
+
I18n.t('zone.chiayi_county', locale: locale)
|
44
44
|
when code.between?(630, 655)
|
45
|
-
I18n.t('zone.yunlin_county')
|
45
|
+
I18n.t('zone.yunlin_county', locale: locale)
|
46
46
|
when code.between?(700, 745)
|
47
|
-
I18n.t('zone.tainan_city')
|
47
|
+
I18n.t('zone.tainan_city', locale: locale)
|
48
48
|
when code.between?(800, 852)
|
49
|
-
I18n.t('zone.kaohsiung_city')
|
49
|
+
I18n.t('zone.kaohsiung_city', locale: locale)
|
50
50
|
when code.between?(880, 885)
|
51
|
-
I18n.t('zone.penghu_county')
|
51
|
+
I18n.t('zone.penghu_county', locale: locale)
|
52
52
|
when code.between?(890, 896)
|
53
|
-
I18n.t('zone.kinmen_county')
|
53
|
+
I18n.t('zone.kinmen_county', locale: locale)
|
54
54
|
when code.between?(900, 947)
|
55
|
-
I18n.t('zone.pingtung_county')
|
55
|
+
I18n.t('zone.pingtung_county', locale: locale)
|
56
56
|
when code.between?(950, 966)
|
57
|
-
I18n.t('zone.taitung_county')
|
57
|
+
I18n.t('zone.taitung_county', locale: locale)
|
58
58
|
when code.between?(970, 983)
|
59
|
-
I18n.t('zone.hualien_county')
|
59
|
+
I18n.t('zone.hualien_county', locale: locale)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def district
|
64
|
-
|
64
|
+
# Code 300 and 600 usages are duplicated.
|
65
|
+
return I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: @locale) unless [300, 600].include?(@code)
|
65
66
|
end
|
66
67
|
|
67
68
|
def address
|
68
|
-
I18n.locale = @locale
|
69
|
-
|
70
69
|
if [300, 600].include?(@code)
|
71
70
|
return self.zone
|
72
71
|
else
|
73
|
-
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}")
|
72
|
+
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: @locale)
|
74
73
|
return "#{self.zone} #{district}"
|
75
74
|
end
|
76
75
|
end
|
76
|
+
|
77
|
+
# Flaggers
|
78
|
+
def is_city?
|
79
|
+
self.zone(locale: :en).end_with?("City")
|
80
|
+
end
|
81
|
+
|
82
|
+
def is_county?
|
83
|
+
!self.is_city?
|
84
|
+
end
|
85
|
+
|
86
|
+
def is_district?
|
87
|
+
return false if [300, 600].include?(@code)
|
88
|
+
|
89
|
+
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: :en)
|
90
|
+
return district.end_with?("District")
|
91
|
+
end
|
92
|
+
|
93
|
+
def is_township?
|
94
|
+
return false if [300, 600].include?(@code)
|
95
|
+
|
96
|
+
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: :en)
|
97
|
+
return district.end_with?("Township")
|
98
|
+
end
|
99
|
+
|
100
|
+
def is_islands?
|
101
|
+
return false if [300, 600].include?(@code)
|
102
|
+
|
103
|
+
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: :en)
|
104
|
+
return district.end_with?("Islands")
|
105
|
+
end
|
77
106
|
end
|
78
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taiwan_address
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DONGSHIH TENG
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|