jp_prefecture 0.8.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- Guardfile
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.8
7
- - 2.2.4
8
- - 2.3.0
9
- - ruby-head
10
- matrix:
11
- allow_failures:
12
- - rvm: ruby-head
13
- fast_finish: true
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- -
2
- CHANGELOG.md
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env rake
2
- # coding: utf-8
3
- require "bundler/gem_tasks"
4
-
5
- task default: [:spec]
6
- begin
7
- require 'rspec/core/rake_task'
8
- RSpec::Core::RakeTask.new(:spec) do |spec|
9
- spec.pattern = 'spec/**/*_spec.rb'
10
- spec.rspec_opts = %w(--format documentation --color)
11
- end
12
- rescue LoadError => e
13
- end
14
-
15
- desc 'zip.yml を作成します'
16
- task :create_zips do
17
- require 'csv'
18
- require 'jp_prefecture'
19
-
20
- file_name = 'ken_all_utf8.csv'
21
-
22
- # download files
23
- `wget http://www.post.japanpost.jp/zipcode/dl/kogaki/lzh/ken_all.lzh`
24
- `lha x ken_all.lzh`
25
- `iconv -f sjis -t utf-8 ken_all.csv > #{file_name}`
26
- `rm ken_all.lzh`
27
- `rm ken_all.csv`
28
-
29
- zips = []
30
-
31
- # read CSV
32
- CSV.foreach(file_name, headers: false) { |line| zips << [line[2], line[6]] }
33
-
34
- # create sorted list of zips -> prefecture_code
35
- zips = zips
36
- .collect { |zip, prefecture| [zip.to_i, JpPrefecture::Prefecture.find(name: prefecture).code] }
37
- .sort{ |x, y| x[0] <=> y[0] }
38
-
39
- # prepare calculation
40
- ranged_zips = []
41
- current = [ zips.first[0], zips.first[0], zips.first[1] ]
42
-
43
- # calculate the zip ranges of each prefecture
44
- zips.each do |zip, code|
45
- if current[2] == code
46
- current[1] = zip
47
- else
48
- ranged_zips << current
49
- current = [zip, zip, code]
50
- end
51
- end
52
-
53
- # add last prefecture
54
- ranged_zips << current
55
-
56
- # create prefecture hash
57
- prefectures_to_zip = {}
58
-
59
- ranged_zips.each do |r0, r1, code|
60
- prefectures_to_zip[code] ||= []
61
- prefectures_to_zip[code] << [r0, r1]
62
- end
63
-
64
- prefectures_to_zip = Hash[*prefectures_to_zip.sort.flatten(1)]
65
-
66
- # save result
67
- File.open('data/zip.yml', 'w') do |file|
68
- file.write "# { prefecture_code: [[from_zip_1, to_zip_1], [from_zip_2, to_zip_2], ...], ... }\n"
69
- file.write prefectures_to_zip.to_yaml
70
- end
71
-
72
- # delete temporary file
73
- `rm #{file_name}`
74
- end
@@ -1,23 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/jp_prefecture/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ['chocoby']
6
- gem.email = ['chocoby@gmail.com']
7
- gem.summary = %q{Convert japan prefecture code into prefecture name}
8
- gem.description = %q{Convert japan prefecture code(JIS X 0402 based) into prefecture name.}
9
- gem.homepage = 'https://github.com/chocoby/jp_prefecture'
10
-
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = 'jp_prefecture'
15
- gem.require_paths = ['lib']
16
- gem.version = JpPrefecture::VERSION
17
-
18
- gem.add_development_dependency 'rake'
19
- gem.add_development_dependency 'rspec', '~> 3.1'
20
- gem.add_development_dependency 'activerecord', '>= 3.2.0'
21
- gem.add_development_dependency 'sqlite3'
22
- gem.add_development_dependency 'coveralls'
23
- end
data/spec/base_spec.rb DELETED
@@ -1,81 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Base do
5
- describe '#jp_prefecture' do
6
- describe 'カラム名の指定について' do
7
- context 'prefecture_code を指定した場合' do
8
- let(:model_class) do
9
- klass = Class.new(ActiveRecord::Base) do
10
- self.table_name = :places
11
- include JpPrefecture
12
- jp_prefecture :prefecture_code
13
- end
14
-
15
- klass.new(prefecture_code: 1)
16
- end
17
-
18
- it 'prefecture_code のコードが変換できること' do
19
- expect(model_class.prefecture.name).to eq '北海道'
20
- end
21
- end
22
-
23
- context 'prefecture_id を指定した場合' do
24
- let(:model_class) do
25
- klass = Class.new(ActiveRecord::Base) do
26
- self.table_name = :places
27
- include JpPrefecture
28
- jp_prefecture :prefecture_id
29
- end
30
-
31
- klass.new(prefecture_id: 1)
32
- end
33
-
34
- it 'prefecture_id のコードが変換できること' do
35
- expect(model_class.prefecture.name).to eq '北海道'
36
- end
37
- end
38
- end
39
-
40
- describe '生成するメソッド名の指定について' do
41
- context 'prefecture_method を指定した場合' do
42
- let(:model_class) do
43
- klass = Class.new(ActiveRecord::Base) do
44
- self.table_name = :places
45
- include JpPrefecture
46
- jp_prefecture :prefecture_code, method_name: :prefecture_method
47
- end
48
-
49
- klass.new(prefecture_code: 1)
50
- end
51
-
52
- it 'prefecture_method で結果が参照できること' do
53
- expect(model_class.prefecture_method.name).to eq '北海道'
54
- end
55
- end
56
- end
57
-
58
- describe '都道府県の検索について' do
59
- let(:klass) do
60
- Class.new(ActiveRecord::Base) do
61
- self.table_name = :places
62
- include JpPrefecture
63
- jp_prefecture :prefecture_code
64
- end
65
- end
66
-
67
- context '都道府県が見つかった場合' do
68
- let(:model_class) { klass.new(prefecture_code: 1) }
69
- it { expect(model_class).to respond_to(:prefecture) }
70
- it { expect(model_class.prefecture).to be_an_instance_of(JpPrefecture::Prefecture) }
71
- it { expect(model_class.prefecture.name).to eq '北海道' }
72
- end
73
-
74
- context '都道府県が見つからなかった場合' do
75
- let(:model_class) { klass.new(prefecture_code: 99) }
76
- it { expect(model_class).to respond_to(:prefecture) }
77
- it { expect(model_class.prefecture).to be_nil }
78
- end
79
- end
80
- end
81
- end
data/spec/config_spec.rb DELETED
@@ -1,18 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Config do
5
- describe '#mapping_data' do
6
- context 'カスタマイズされたprefecture.ymlを使うとき' do
7
- before do
8
- filepath = File.join(File.dirname(__FILE__), 'fixtures/prefecture.yml')
9
- @config = described_class.new
10
- @config.mapping_data = YAML.load_file filepath
11
- end
12
-
13
- it '都道府県+海外の数が48であること' do
14
- expect(@config.mapping_data.count).to eq 48
15
- end
16
- end
17
- end
18
- end
@@ -1,148 +0,0 @@
1
- # JIS X 0402 で定義されている都道府県コードと都道府県名をベースに
2
- # コードがゼロから始まるもの(09 など)を 1 ケタにし、
3
- # さらに、「海外」をcode: 48として追加したもの
4
- ---
5
- 1:
6
- :name: 北海道
7
- :name_e: hokkaido
8
- 2:
9
- :name: 青森県
10
- :name_e: aomori
11
- 3:
12
- :name: 岩手県
13
- :name_e: iwate
14
- 4:
15
- :name: 宮城県
16
- :name_e: miyagi
17
- 5:
18
- :name: 秋田県
19
- :name_e: akita
20
- 6:
21
- :name: 山形県
22
- :name_e: yamagata
23
- 7:
24
- :name: 福島県
25
- :name_e: fukushima
26
- 8:
27
- :name: 茨城県
28
- :name_e: ibaraki
29
- 9:
30
- :name: 栃木県
31
- :name_e: tochigi
32
- 10:
33
- :name: 群馬県
34
- :name_e: gunma
35
- 11:
36
- :name: 埼玉県
37
- :name_e: saitama
38
- 12:
39
- :name: 千葉県
40
- :name_e: chiba
41
- 13:
42
- :name: 東京都
43
- :name_e: tokyo
44
- 14:
45
- :name: 神奈川県
46
- :name_e: kanagawa
47
- 15:
48
- :name: 新潟県
49
- :name_e: niigata
50
- 16:
51
- :name: 富山県
52
- :name_e: toyama
53
- 17:
54
- :name: 石川県
55
- :name_e: ishikawa
56
- 18:
57
- :name: 福井県
58
- :name_e: fukui
59
- 19:
60
- :name: 山梨県
61
- :name_e: yamanashi
62
- 20:
63
- :name: 長野県
64
- :name_e: nagano
65
- 21:
66
- :name: 岐阜県
67
- :name_e: gifu
68
- 22:
69
- :name: 静岡県
70
- :name_e: shizuoka
71
- 23:
72
- :name: 愛知県
73
- :name_e: aichi
74
- 24:
75
- :name: 三重県
76
- :name_e: mie
77
- 25:
78
- :name: 滋賀県
79
- :name_e: shiga
80
- 26:
81
- :name: 京都府
82
- :name_e: kyoto
83
- 27:
84
- :name: 大阪府
85
- :name_e: osaka
86
- 28:
87
- :name: 兵庫県
88
- :name_e: hyogo
89
- 29:
90
- :name: 奈良県
91
- :name_e: nara
92
- 30:
93
- :name: 和歌山県
94
- :name_e: wakayama
95
- 31:
96
- :name: 鳥取県
97
- :name_e: tottori
98
- 32:
99
- :name: 島根県
100
- :name_e: shimane
101
- 33:
102
- :name: 岡山県
103
- :name_e: okayama
104
- 34:
105
- :name: 広島県
106
- :name_e: hiroshima
107
- 35:
108
- :name: 山口県
109
- :name_e: yamaguchi
110
- 36:
111
- :name: 徳島県
112
- :name_e: tokushima
113
- 37:
114
- :name: 香川県
115
- :name_e: kagawa
116
- 38:
117
- :name: 愛媛県
118
- :name_e: ehime
119
- 39:
120
- :name: 高知県
121
- :name_e: kochi
122
- 40:
123
- :name: 福岡県
124
- :name_e: fukuoka
125
- 41:
126
- :name: 佐賀県
127
- :name_e: saga
128
- 42:
129
- :name: 長崎県
130
- :name_e: nagasaki
131
- 43:
132
- :name: 熊本県
133
- :name_e: kumamoto
134
- 44:
135
- :name: 大分県
136
- :name_e: oita
137
- 45:
138
- :name: 宮崎県
139
- :name_e: miyazaki
140
- 46:
141
- :name: 鹿児島県
142
- :name_e: kagoshima
143
- 47:
144
- :name: 沖縄県
145
- :name_e: okinawa
146
- 48:
147
- :name: 海外
148
- :name_e: foreign_country
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture do
5
- describe '.included' do
6
- subject do
7
- Class.new(ActiveRecord::Base) do
8
- include JpPrefecture
9
- end
10
- end
11
-
12
- it { is_expected.to respond_to(:jp_prefecture) }
13
- end
14
-
15
- describe 'include されていない' do
16
- subject { Class.new(ActiveRecord::Base) }
17
- it { is_expected.not_to respond_to(:jp_prefecture) }
18
- end
19
-
20
- describe '.setup' do
21
- before do
22
- filepath = File.join(File.dirname(__FILE__), 'fixtures/prefecture.yml')
23
- JpPrefecture.setup do |config|
24
- config.mapping_data = YAML.load_file filepath
25
- end
26
- end
27
-
28
- after do
29
- JpPrefecture.setup do |config|
30
- config.mapping_data = nil
31
- end
32
- end
33
-
34
- it { expect(JpPrefecture::Mapping.data.count).to eq 48 }
35
- end
36
- end
data/spec/mapping_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Mapping do
5
- describe '.data' do
6
- it '都道府県の数が47であること' do
7
- expect(described_class.data.count).to eq 47
8
- end
9
- end
10
- end