jp_prefecture 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6636c60d594d140725ac2f9b01c6724b66328e3
4
- data.tar.gz: dfb83ab23f2bb8be09afc748d17f3b51180e2e7b
3
+ metadata.gz: 2969a6cc0162ae5a97f2bd4205ae05ce500a2124
4
+ data.tar.gz: 347d5c47c228762af40e5804d476dc94d8f6e2ea
5
5
  SHA512:
6
- metadata.gz: d8e91fddb44bc5cfbce465c541a5ca3312afaf8412900fbf122591a64a2215f1b29900d4437149a800be5d67ba28e0ceaaa37cae7c1c7cfe8d2eeafdfaa257d8
7
- data.tar.gz: c5fa940c3614cb491f32f5bf740e2140a02dde3ca8f42af4bb8adcdf5da941ad09470f298042702760a07afeabc3d507237e6349805655368d801e0b286f3791
6
+ metadata.gz: 5856a351b31f85dd6691f3b0494867023c2d60ccd099d165f5f511a06edc628f67227dd3bc96fd5029a2a8cacc70e21a3d8a3aa3209204fcf8f01f14d885edee
7
+ data.tar.gz: fd18d884336e9b812daa06b1ad4b9af27838bdacf1daf0367030ff5ad981297a2a48f9523279b8b3244cd29ccfa340a2285c1af290e2a6b1905a13fe222c894c
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -16,3 +17,4 @@ test/tmp
16
17
  test/version_tmp
17
18
  tmp
18
19
  Guardfile
20
+ gemfiles/*.lock
@@ -1,13 +1,32 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ cache: bundler
3
4
  rvm:
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.8
7
8
  - 2.2.4
8
- - 2.3.0
9
+ - 2.3.3
10
+ - 2.4.0
9
11
  - ruby-head
12
+ gemfile:
13
+ - gemfiles/rails32.gemfile
14
+ - gemfiles/rails40.gemfile
15
+ - gemfiles/rails41.gemfile
16
+ - gemfiles/rails42.gemfile
17
+ - gemfiles/rails50.gemfile
10
18
  matrix:
11
19
  allow_failures:
20
+ - rvm: 1.9.3
12
21
  - rvm: ruby-head
13
22
  fast_finish: true
23
+ exclude:
24
+ - rvm: 1.9.3
25
+ gemfile: gemfiles/rails50.gemfile
26
+ - rvm: 2.0.0
27
+ gemfile: gemfiles/rails50.gemfile
28
+ - rvm: 2.1.8
29
+ gemfile: gemfiles/rails50.gemfile
30
+ notifications:
31
+ email:
32
+ - false
@@ -0,0 +1,21 @@
1
+ appraise 'rails32' do
2
+ gem 'activerecord', '~> 3.2.0'
3
+ end
4
+
5
+ appraise 'rails40' do
6
+ gem 'activerecord', '~> 4.0.0'
7
+ end
8
+
9
+ appraise 'rails41' do
10
+ gem 'activerecord', '~> 4.1.0'
11
+ end
12
+
13
+ appraise 'rails42' do
14
+ gem 'activerecord', '~> 4.2.0'
15
+ end
16
+
17
+ if RUBY_VERSION >= '2.2.2'
18
+ appraise 'rails50' do
19
+ gem 'activerecord', '~> 5.0.0'
20
+ end
21
+ end
@@ -1,3 +1,10 @@
1
+ ## Unreleased
2
+
3
+ ## 0.9.0 (Jan 15, 2017)
4
+
5
+ * Add English Readme (Issue [#21](https://github.com/chocoby/jp_prefecture/issues/21)/PR [#22](https://github.com/chocoby/jp_prefecture/pull/22)/[@PeterTeng](https://github.com/PeterTeng))
6
+ * 都道府県情報に種類を追加 (PR [#23](https://github.com/chocoby/jp_prefecture/pull/23)/[@gazayas](https://github.com/gazayas))
7
+
1
8
  ## 0.8.1 (Mar 30, 2016)
2
9
 
3
10
  * `JpPrefecture::Prefecture.find(name: name)` に `nil` や空文字を渡した時に `nil` を返す (Issue [#18](https://github.com/chocoby/jp_prefecture/issues/18)/PR [#19](https://github.com/chocoby/jp_prefecture/pull/19)/[@k-motoyan](https://github.com/k-motoyan))
File without changes
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # JpPrefecture
2
2
 
3
+ [**English**](README_EN.md)
4
+
3
5
  [![Gem Version](http://img.shields.io/gem/v/jp_prefecture.svg?style=flat)](https://rubygems.org/gems/jp_prefecture)
4
6
  [![Build Status](http://img.shields.io/travis/chocoby/jp_prefecture/master.svg?style=flat)](https://travis-ci.org/chocoby/jp_prefecture)
5
7
  [![Coveralls](https://img.shields.io/coveralls/chocoby/jp_prefecture.svg)](https://coveralls.io/r/chocoby/jp_prefecture)
@@ -27,21 +29,6 @@ JIS X 0402 で定義されている都道府県コードをベースに、
27
29
 
28
30
  また、Rails のプラグインとして使用することもできます。
29
31
 
30
- ## インストール
31
-
32
- 以下の行を `Gemfile` に記述してから:
33
-
34
- ```
35
- gem 'jp_prefecture'
36
- ```
37
-
38
- `bundle` を実行してください。
39
-
40
- または、手動でインストールしてください:
41
-
42
- ```
43
- $ gem install jp_prefecture
44
- ```
45
32
 
46
33
  ## 使い方
47
34
 
@@ -70,6 +57,8 @@ pref.name_k
70
57
  # => "トウキョウト"
71
58
  pref.area
72
59
  # => "関東"
60
+ pref.type
61
+ # => "都"
73
62
  ```
74
63
 
75
64
  以下のように書くことも可能です:
@@ -172,18 +161,33 @@ end
172
161
 
173
162
  マッピングデータのフォーマットについては [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) を参考にしてください。
174
163
 
175
- ## ドキュメント
176
164
 
177
- [http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
165
+ ## インストール
178
166
 
179
- ## TODO
167
+ 以下の行を `Gemfile` に記述してから:
180
168
 
181
- GitHub の [Issues](https://github.com/chocoby/jp_prefecture/issues) を参照してください。
169
+ ```
170
+ gem 'jp_prefecture'
171
+ ```
172
+
173
+ `bundle` を実行してください。
174
+
175
+ または、手動でインストールしてください:
176
+
177
+ ```
178
+ $ gem install jp_prefecture
179
+ ```
180
+
181
+
182
+ ## ドキュメント
183
+
184
+ [http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
182
185
 
183
186
  ## サポートしているバージョン
184
187
 
185
- * Ruby: 1.9.3 / 2.0.0 / 2.1 / 2.2 / 2.3
186
- * Rails: 3.2 / 4.0 / 4.1 / 4.2
188
+ * Ruby: 1.9.3 / 2.0.0 / 2.1 / 2.2 / 2.3 / 2.4
189
+ * Rails: 3.2 / 4.0 / 4.1 / 4.2 / 5.0
190
+
187
191
 
188
192
  ## Contributing
189
193
 
@@ -193,6 +197,7 @@ GitHub の [Issues](https://github.com/chocoby/jp_prefecture/issues) を参照
193
197
  4. Push to the branch (`git push origin my-new-feature`)
194
198
  5. Create new Pull Request
195
199
 
200
+
196
201
  ## テスト
197
202
 
198
203
  ```
@@ -202,10 +207,14 @@ bundle install --path .bundle
202
207
  bundle exec rspec
203
208
  ```
204
209
 
205
- ## GitHub
210
+ 複数バージョンの Active Record でテストを実行:
206
211
 
207
- https://github.com/chocoby/jp_prefecture
212
+ ```
213
+ bundle exec appraisal install
214
+ bundle exec appraisal rake spec
215
+ ```
208
216
 
209
- ## ライセンス
210
217
 
211
- [MIT License](http://chocoby.mit-license.org/)
218
+ ## GitHub
219
+
220
+ https://github.com/chocoby/jp_prefecture
@@ -0,0 +1,219 @@
1
+ # JpPrefecture
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/jp_prefecture.svg?style=flat)](https://rubygems.org/gems/jp_prefecture)
4
+ [![Build Status](http://img.shields.io/travis/chocoby/jp_prefecture/master.svg?style=flat)](https://travis-ci.org/chocoby/jp_prefecture)
5
+ [![Coveralls](https://img.shields.io/coveralls/chocoby/jp_prefecture.svg)](https://coveralls.io/r/chocoby/jp_prefecture)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/chocoby/jp_prefecture.svg)](https://codeclimate.com/github/chocoby/jp_prefecture)
7
+ [![Dependency Status](http://img.shields.io/gemnasium/chocoby/jp_prefecture.svg?style=flat)](https://gemnasium.com/chocoby/jp_prefecture)
8
+
9
+ https://rubygems.org/gems/jp_prefecture
10
+
11
+ ## Description
12
+
13
+ Convert prefecture code to prefecture name in Japan.
14
+
15
+ Based on JIS X 0402. Remove 0 when prefecture code start with 0.
16
+
17
+ ```
18
+ Hokkaido: 01 -> 1
19
+ Tokyo: 13 -> 13
20
+ ```
21
+
22
+ Reference(Japanese): [Wikipedia: 全国地方公共団体コード](http://ja.wikipedia.org/wiki/%E5%85%A8%E5%9B%BD%E5%9C%B0%E6%96%B9%E5%85%AC%E5%85%B1%E5%9B%A3%E4%BD%93%E3%82%B3%E3%83%BC%E3%83%89#.E9.83.BD.E9.81.93.E5.BA.9C.E7.9C.8C.E3.82.B3.E3.83.BC.E3.83.89)
23
+
24
+ You can change prefecture code and prefecture name's mapping data. Please check this [Customize mapping data](#customize-mapping-data)
25
+
26
+ Also available as a Rails plugin
27
+
28
+ ## Usage
29
+
30
+ ### Requirement
31
+
32
+ ```ruby
33
+ require 'jp_prefecture'
34
+ ```
35
+
36
+ ### Search Prefecture by Code
37
+
38
+ Provide prefecture code to search prefecture's data
39
+
40
+ ```ruby
41
+ pref = JpPrefecture::Prefecture.find 13
42
+ # => #<JpPrefecture::Prefecture:0x007fceb11927d8 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035], @area="関東">
43
+ pref.code
44
+ # => 13
45
+ pref.name
46
+ # => "東京都"
47
+ pref.name_e
48
+ # => "Tokyo"
49
+ pref.name_h
50
+ # => "とうきょうと"
51
+ pref.name_k
52
+ # => "トウキョウト"
53
+ pref.area
54
+ # => "関東"
55
+ pref.type
56
+ # => "都"
57
+ ```
58
+
59
+ or
60
+
61
+ ```ruby
62
+ JpPrefecture::Prefecture.find code: 13
63
+ ```
64
+
65
+ ### Search by Prefecture Name
66
+
67
+ ```ruby
68
+ JpPrefecture::Prefecture.find name: "東京都"
69
+ JpPrefecture::Prefecture.find name: "Tokyo"
70
+ JpPrefecture::Prefecture.find name: "tokyo"
71
+ JpPrefecture::Prefecture.find name: "トウキョウト"
72
+ JpPrefecture::Prefecture.find name: "とうきょうと"
73
+ JpPrefecture::Prefecture.find name: "東京"
74
+ ```
75
+
76
+ ### All Prefectures
77
+
78
+ ```ruby
79
+ JpPrefecture::Prefecture.all
80
+ # => [#<JpPrefecture::Prefecture:0x007fceb119a2a8 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">, ...]
81
+ ```
82
+
83
+ ### Usage on Rails (ActiveRecord)
84
+
85
+ Include JpPrefecture to Model which `ActiveRecord::Base` inherited.
86
+
87
+ app/models/place.rb:
88
+
89
+ ```ruby
90
+ class Place < ActiveRecord::Base
91
+ # prefecture_code:integer
92
+
93
+ include JpPrefecture
94
+ jp_prefecture :prefecture_code
95
+ end
96
+ ```
97
+
98
+ By JpPrefecture included, `prefecture` method will be generated:
99
+
100
+ ```ruby
101
+ place = Place.new
102
+ place.prefecture_code = 13
103
+ place.prefecture.name_e
104
+ # => "Tokyo"
105
+ ```
106
+
107
+ Customize `prefecture` method name with `method_name` option:
108
+
109
+ ```ruby
110
+ # model
111
+ jp_prefecture :prefecture_code, method_name: :pref
112
+
113
+ place = Place.new
114
+ place.prefecture_code = 13
115
+ place.pref.name_e
116
+ # => "Tokyo"
117
+ ```
118
+
119
+ ### Template usage
120
+
121
+ Use `collection_select` to generate selector in view:
122
+
123
+ ```ruby
124
+ # Selector prefecture name in English
125
+ f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name_e
126
+
127
+ # Selector prefecture name in Japanese
128
+ f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name
129
+ ```
130
+
131
+ ### Migration
132
+
133
+ Set `prefecture_code` column type to `integer` or `string`.
134
+
135
+ Example:
136
+
137
+ ```ruby
138
+ class AddPrefectureCodeToPlaces < ActiveRecord::Migration
139
+ def change
140
+ add_column :places, :prefecture_code, :integer
141
+ end
142
+ end
143
+ ```
144
+
145
+ ### Customize Mapping Data
146
+
147
+ Customize mapping data with `custom_mapping_path`.
148
+
149
+ ```ruby
150
+ custom_mapping_path = "..." # /path/to/mapping_data
151
+
152
+ JpPrefecture.setup do |config|
153
+ config.mapping_data = YAML.load_file custom_mapping_path
154
+ end
155
+ ```
156
+
157
+ Check out [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) for data format.
158
+
159
+
160
+ ## Installation
161
+
162
+ Add this line in Gemfile.
163
+
164
+ ```ruby
165
+ gem 'jp_prefecture'
166
+ ```
167
+
168
+ Run
169
+
170
+ ```
171
+ $ bundle
172
+ ```
173
+
174
+ Or install gem with `gem install`
175
+
176
+ ```
177
+ $ gem install jp_prefecture
178
+ ```
179
+
180
+
181
+ ## Documentation
182
+
183
+ [http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
184
+
185
+ ## Supports
186
+
187
+ * Ruby: 1.9.3 / 2.0.0 / 2.1 / 2.2 / 2.3
188
+ * Rails: 3.2 / 4.0 / 4.1 / 4.2 / 5.0
189
+
190
+
191
+ ## Contributing
192
+
193
+ 1. Fork it
194
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
195
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
196
+ 4. Push to the branch (`git push origin my-new-feature`)
197
+ 5. Create new Pull Request
198
+
199
+
200
+ ## Test
201
+
202
+ ```
203
+ git clone https://github.com/chocoby/jp_prefecture.git
204
+ cd jp_prefecture
205
+ bundle install --path .bundle
206
+ bundle exec rspec
207
+ ```
208
+
209
+ Run test in multiple `ActiveRecord` versions
210
+
211
+ ```
212
+ bundle exec appraisal install
213
+ bundle exec appraisal rake spec
214
+ ```
215
+
216
+
217
+ ## GitHub
218
+
219
+ https://github.com/chocoby/jp_prefecture
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency 'activerecord', '>= 3.2.0'
21
21
  gem.add_development_dependency 'sqlite3'
22
22
  gem.add_development_dependency 'coveralls'
23
+ gem.add_development_dependency 'appraisal'
23
24
  end
@@ -6,7 +6,7 @@ module JpPrefecture
6
6
  # 都道府県のコードと名前を扱うクラス
7
7
  class Prefecture
8
8
 
9
- attr_accessor :code, :name, :name_e, :name_h, :name_k, :zips, :area
9
+ attr_accessor :code, :name, :name_e, :name_h, :name_k, :zips, :area, :type
10
10
 
11
11
  # 配列から都道府県クラスを生成
12
12
  #
@@ -31,6 +31,13 @@ module JpPrefecture
31
31
  pref.name_k = name_k
32
32
  pref.zips = ZipMapping.data[code]
33
33
  pref.area = area
34
+ pref.type =
35
+ case pref.name[-1]
36
+ when "都", "道", "府", "県"
37
+ pref.name[-1]
38
+ else
39
+ nil
40
+ end
34
41
 
35
42
  pref
36
43
  end
@@ -1,3 +1,3 @@
1
1
  module JpPrefecture
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -11,6 +11,17 @@ describe JpPrefecture::Prefecture do
11
11
  it { expect(pref.name_k).to eq 'ホッカイドウ' }
12
12
  it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
13
13
  it { expect(pref.area).to eq '北海道' }
14
+ it { expect(pref.type).to eq '道' }
15
+
16
+ let(:nil_type_pref) { JpPrefecture::Prefecture.build(13, '東京', 'Tokyo', 'とうきょう', 'トウキョウ', '関東') }
17
+ it { expect(nil_type_pref.code).to eq 13 }
18
+ it { expect(nil_type_pref.name).to eq '東京' }
19
+ it { expect(nil_type_pref.name_e).to eq 'Tokyo' }
20
+ it { expect(nil_type_pref.name_h).to eq 'とうきょう' }
21
+ it { expect(nil_type_pref.name_k).to eq 'トウキョウ' }
22
+ it { expect(nil_type_pref.zips).to eq [1000000..2080035] }
23
+ it { expect(nil_type_pref.area).to eq '関東' }
24
+ it { expect(nil_type_pref.type).to eq nil }
14
25
  end
15
26
 
16
27
  describe '.find' do
@@ -24,6 +35,7 @@ describe JpPrefecture::Prefecture do
24
35
  it { expect(pref.name_k).to eq 'ホッカイドウ' }
25
36
  it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
26
37
  it { expect(pref.area).to eq '北海道' }
38
+ it { expect(pref.type).to eq '道' }
27
39
  end
28
40
 
29
41
  shared_examples '都道府県が見つからない' do |arg|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp_prefecture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chocoby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Convert japan prefecture code(JIS X 0402 based) into prefecture name.
84
98
  email:
85
99
  - chocoby@gmail.com
@@ -91,13 +105,20 @@ files:
91
105
  - ".rspec"
92
106
  - ".travis.yml"
93
107
  - ".yardopts"
108
+ - Appraisals
94
109
  - CHANGELOG.md
95
110
  - Gemfile
96
- - LICENSE
111
+ - MIT-LICENSE
97
112
  - README.md
113
+ - README_EN.md
98
114
  - Rakefile
99
115
  - data/prefecture.yml
100
116
  - data/zip.yml
117
+ - gemfiles/rails32.gemfile
118
+ - gemfiles/rails40.gemfile
119
+ - gemfiles/rails41.gemfile
120
+ - gemfiles/rails42.gemfile
121
+ - gemfiles/rails50.gemfile
101
122
  - jp_prefecture.gemspec
102
123
  - lib/jp_prefecture.rb
103
124
  - lib/jp_prefecture/base.rb
@@ -133,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
154
  version: '0'
134
155
  requirements: []
135
156
  rubyforge_project:
136
- rubygems_version: 2.4.5.1
157
+ rubygems_version: 2.6.8
137
158
  signing_key:
138
159
  specification_version: 4
139
160
  summary: Convert japan prefecture code into prefecture name