world_postal_codes 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ load(File.expand_path(File.join(File.dirname(__FILE__), '../world_postal_codes/tasks.rb')))
@@ -0,0 +1,19 @@
1
+ require "yaml"
2
+
3
+ module WorldPostalCodes
4
+ module Identify
5
+ def jp(code)
6
+ db[code] || {}
7
+ end
8
+
9
+ def db
10
+ @db ||= begin
11
+ YAML.load(File.open(DATA_DIR))
12
+ end
13
+ end
14
+
15
+ def load
16
+ db
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+ require "zip"
3
+ require "csv"
4
+ require 'nkf'
5
+ require 'yaml'
6
+
7
+ module WorldPostalCodes
8
+ module Import
9
+ class << self
10
+
11
+ def run!
12
+ postal_codes = []
13
+ Zip::File.open(open(WorldPostalCodes::ZIP_URL).path) do |zip|
14
+ file = zip.glob('*.CSV').first
15
+ CSV.parse(file.get_input_stream.read, encoding: "UTF-8") do |row|
16
+ postal_codes << convert(row)
17
+ end
18
+ end
19
+ write(postal_codes.to_h)
20
+ end
21
+
22
+ private
23
+ def convert(row)
24
+ [
25
+ row[2].to_s,
26
+ {
27
+ prefecture: NKF.nkf('-S -w', row[6]),
28
+ prefecture_kana: NKF.nkf('-S -w', row[3]),
29
+ city: NKF.nkf('-S -w', row[7]),
30
+ city_kana: NKF.nkf('-S -w', row[4])
31
+ }
32
+ ]
33
+ end
34
+
35
+ def write(postal_codes)
36
+ File.open(WorldPostalCodes::DATA_DIR, "wb") do |file|
37
+ file.write postal_codes.to_yaml
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module WorldPostalCodes
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ require File.expand_path('../tasks', __FILE__)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require "world_postal_codes/import"
2
+
3
+ namespace :postal_codes do
4
+ desc "download zip and convert to yaml"
5
+ task :import_jp do
6
+ WorldPostalCodes::Import.run!
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module WorldPostalCodes
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "world_postal_codes/identify"
2
+ require "pry"
3
+ require "yaml"
4
+
5
+ module WorldPostalCodes
6
+ DATA_DIR = File.dirname(__FILE__) + '/../data/japan.yml'
7
+ ZIP_URL = "http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip"
8
+ extend WorldPostalCodes::Identify
9
+
10
+ # class << self
11
+ # def identify(code)
12
+ # db[code] || {}
13
+ # end
14
+
15
+ # def db
16
+ # @db ||= begin
17
+ # YAML.load(File.open(DATA_DIR))
18
+ # end
19
+ # end
20
+
21
+ # def load
22
+ # db
23
+ # end
24
+ # end
25
+
26
+ end
27
+ require 'world_postal_codes/railtie' if defined?(Rails)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'world_postal_codes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "world_postal_codes"
8
+ spec.version = WorldPostalCodes::VERSION
9
+ spec.authors = ["kawasaki-atsushi"]
10
+ spec.email = ["kawasaki8910@gmail.com"]
11
+
12
+ spec.summary = %s(Simple gem to get city for a given Japan postal codes.)
13
+ spec.description = %s(Gem to identify zip codes inside Japan)
14
+ spec.homepage = "https://github.com/kawasakiatsushi/world_postal_codes"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rubyzip"
23
+ spec.add_dependency "pry"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: world_postal_codes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - kawasaki-atsushi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Gem to identify zip codes inside Japan
84
+ email:
85
+ - kawasaki8910@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - data/japan.yml
100
+ - lib/tasks/world_postal_codes_task.rake
101
+ - lib/world_postal_codes.rb
102
+ - lib/world_postal_codes/identify.rb
103
+ - lib/world_postal_codes/import.rb
104
+ - lib/world_postal_codes/railtie.rb
105
+ - lib/world_postal_codes/tasks.rb
106
+ - lib/world_postal_codes/version.rb
107
+ - world_postal_codes.gemspec
108
+ homepage: https://github.com/kawasakiatsushi/world_postal_codes
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.4
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Simple gem to get city for a given Japan postal codes.
132
+ test_files: []
133
+ has_rdoc: