jisx0402 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Jisx0402
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/jisx0402.rb CHANGED
@@ -2,6 +2,7 @@ require "jisx0402/version"
2
2
  require 'jisx0402/district_array'
3
3
  require 'jisx0402/tree'
4
4
  require 'msgpack'
5
+ require 'json'
5
6
 
6
7
  module Jisx0402
7
8
  class << self
@@ -42,7 +43,7 @@ module Jisx0402
42
43
  end
43
44
 
44
45
  def data
45
- @@data ||= open_msgpack_data('jisx0402.msgpack').map do |d|
46
+ @@data ||= open_data('jisx0402').map do |d|
46
47
  Code.new(d)
47
48
  end
48
49
  end
@@ -69,7 +70,21 @@ module Jisx0402
69
70
  end
70
71
 
71
72
  def jisx0402_to_zipcode_table
72
- @@jisx0402_to_zipcode_table ||= open_msgpack_data('jisx0402_to_zipcode.msgpack')
73
+ @@jisx0402_to_zipcode_table ||= open_data('jisx0402_to_zipcode')
74
+ end
75
+
76
+ def open_data(fname)
77
+ if Gem::Version.new(MessagePack::VERSION) > Gem::Version.new('0.5.11')
78
+ open_msgpack_data("#{fname}.msgpack")
79
+ else
80
+ open_json_data("#{fname}.json")
81
+ end
82
+ end
83
+
84
+ def open_json_data(fname)
85
+ JSON.parse(
86
+ open(File.expand_path("../data/#{fname}", __FILE__)).read
87
+ )
73
88
  end
74
89
 
75
90
  def open_msgpack_data(fname)
@@ -77,6 +92,12 @@ module Jisx0402
77
92
  open(File.expand_path("../data/#{fname}", __FILE__)).read
78
93
  )
79
94
  end
95
+
96
+ def warmup
97
+ match_by_zipcode('0')
98
+ forward_match_by_full('東')
99
+ true
100
+ end
80
101
  end
81
102
 
82
103
  class Code
@@ -127,3 +148,5 @@ module Jisx0402
127
148
  end
128
149
  end
129
150
  end
151
+
152
+ Jisx0402.warmup
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.0.1
4
+ version: 1.1.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-02-22 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -98,7 +98,9 @@ files:
98
98
  - bin/setup
99
99
  - jisx0402.gemspec
100
100
  - lib/data/data.csv
101
+ - lib/data/jisx0402.json
101
102
  - lib/data/jisx0402.msgpack
103
+ - lib/data/jisx0402_to_zipcode.json
102
104
  - lib/data/jisx0402_to_zipcode.msgpack
103
105
  - lib/jisx0402.rb
104
106
  - lib/jisx0402/district_array.rb