jisx0402 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26f222f7c4d13c8cc3c688882b7781dd4ab889a1
4
- data.tar.gz: e8c977c6bf60f7a210792042ce7fc6d7c4245bbd
3
+ metadata.gz: cd262b9bf6cddc56cf73871c49364a6ec13987d4
4
+ data.tar.gz: 223a359bfdd1be71794138d842f47ce6dc37e065
5
5
  SHA512:
6
- metadata.gz: c9b1ebf30cddd6b3667fea0afe4a43dc17455c545ef63c035d05e89333324608bfefbb3725e7d22620cc7e02ad423b44bf8f4447b16668a9eaf181c8360e8721
7
- data.tar.gz: d92d57af91e005f284ba356ecb299087a7ca28c46306bda9e711dc214664687d8e2ebb043f4a3a9c292ba4be88192f14299bda92892617a3cbab8c0e2b393070
6
+ metadata.gz: f9a70e935fb241eb69e21f2d1bbfe1d17cba26e40e427e5d3b14b11177e44a713eeea1ba5dddc9e97672a1fcd5886b3d8562325a610ab5af2a87532e4d41f449
7
+ data.tar.gz: c999eedc62ef3442956ea5410fad7c0ef289f6fc4e68364b458aa6898edb2c7186dc8378a9bdae6f29f27613021099a2006e33ce2582bb65bad9fa0d57eeff26
data/lib/jisx0402.rb CHANGED
@@ -124,7 +124,30 @@ module Jisx0402
124
124
  end
125
125
 
126
126
  def code_without_checkdigit
127
- @row[0][0..-2]
127
+ code[0..-2]
128
+ end
129
+
130
+ def district_code
131
+ @district_code ||= code[2..4]
132
+ end
133
+
134
+ def prefecture?
135
+ district_code == '000'.freeze
136
+ end
137
+
138
+ GOVERNMENT_ORDINANCE_DESIGNATED_CITY_CODE_LIST = %(100 130 140 150).freeze
139
+ def government_ordinance_designated_city?
140
+ @government_ordinance_designated_city ||= begin
141
+ GOVERNMENT_ORDINANCE_DESIGNATED_CITY_CODE_LIST.include?(district_code)
142
+ end
143
+ end
144
+
145
+ def ward?
146
+ @ward ||= (100..199).cover?(district_code.to_i)
147
+ end
148
+
149
+ def prefecture_code
150
+ code[0..1]
128
151
  end
129
152
 
130
153
  def prefecture(hiragana: false)
@@ -146,7 +169,19 @@ module Jisx0402
146
169
  def zipcodes
147
170
  Jisx0402.jisx0402_to_zipcode_table[code_without_checkdigit] || []
148
171
  end
172
+
173
+ def cover?(c)
174
+ area_code = c.to_s
175
+ if prefecture?
176
+ area_code.start_with?(prefecture_code)
177
+ elsif government_ordinance_designated_city?
178
+ Jisx0402.forward_match_by_full(full).codes.include?(area_code)
179
+ else
180
+ code == area_code
181
+ end
182
+ end
149
183
  end
150
184
  end
151
185
 
186
+ # Warmpup zipcodes converting table and district codes tree cache.
152
187
  Jisx0402.warmup
@@ -8,4 +8,8 @@ class Jisx0402::DistrictArray < Array
8
8
  def zipcodes
9
9
  self.map(&:zipcodes).flatten.uniq.compact
10
10
  end
11
+
12
+ def codes
13
+ self.map(&:code).flatten.uniq.compact
14
+ end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Jisx0402
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jisx0402
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cnosuke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack