japan_postcoder 0.1.3 β 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -18
- data/japan_postcoder.gemspec +2 -3
- data/lib/japan_postcoder/address.rb +31 -29
- data/lib/japan_postcoder.rb +9 -3
- data/lib/version.rb +1 -1
- metadata +3 -7
- data/CHANGELOG.md +0 -3
- data/japan_postcoder-0.1.0.gem +0 -0
- data/japan_postcoder-0.1.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3e586650b4f5341b900ad823ee293bfd2f8657add741f38b547ff40c12efbca
|
4
|
+
data.tar.gz: a85ca2b8f88ae9c68f230dc9db5e76d6da19800087d8f6c43eb7302cc9036d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c42fdfa2a7728f0cee86f28aa86e1e68ff6c11793272eb9977d9168689c7f8de0d1a8ef68859fe70cd19442b7d664781880a65452313479bb05a7c5eafad91e
|
7
|
+
data.tar.gz: cade322ce15eb46ce73b119bd25b630da8209b526fc4bd29f8065f551abe94d9bc7f38ab1e79a199c5cfb9f6ce1898b1152ebbf1820b0535724e102efde341e8
|
data/README.md
CHANGED
@@ -1,35 +1,82 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a>
|
3
|
+
<img src="https://static.vecteezy.com/system/resources/thumbnails/004/587/562/small_2x/doodle-freehand-drawing-of-japan-map-free-vector.jpg" width="60" />
|
4
|
+
</a>
|
5
|
+
</p>
|
6
|
+
<h1 align="center">
|
7
|
+
π―π΅ Japan Postcoder
|
8
|
+
</h1>
|
2
9
|
|
3
|
-
|
10
|
+
[![Tests](https://github.com/tonystrawberry/japan_postcoder/workflows/Ruby/badge.svg)](https://github.com/tonystrawberry/japan_postcoder/actions/workflows/main.yml)
|
11
|
+
<a href="https://codeclimate.com/github/tonystrawberry/japan_postcoder/maintainability"><img src="https://api.codeclimate.com/v1/badges/7362475ad52048cbbee1/maintainability" /></a>
|
12
|
+
<a href="https://codeclimate.com/github/tonystrawberry/japan_postcoder/test_coverage"><img src="https://api.codeclimate.com/v1/badges/7362475ad52048cbbee1/test_coverage" /></a>
|
4
13
|
|
5
|
-
|
14
|
+
Japan Postcoder is a library that allows you to get the address of a location in Japan from its postcode.
|
15
|
+
It will help you get the prefecture, city, ward and street name from a postcode.
|
6
16
|
|
7
|
-
|
17
|
+
All the location data is provided by the [Japan Post](https://www.post.japanpost.jp/zipcode/download.html)
|
8
18
|
|
9
|
-
|
19
|
+
Rubygems link is here: https://rubygems.org/gems/japan_postcoder
|
10
20
|
|
11
|
-
|
21
|
+
# ππ» Getting started
|
12
22
|
|
13
|
-
|
23
|
+
Start by including `japan-postcoder` in your project:
|
14
24
|
|
15
|
-
|
25
|
+
```bash
|
26
|
+
gem 'japan-postcoder'
|
27
|
+
```
|
16
28
|
|
17
|
-
|
29
|
+
Then, you can use the `JapanPostcoder` class to get the address of a location in Japan from its postcode:
|
18
30
|
|
19
|
-
|
31
|
+
# π¨π»βπ» Usage
|
20
32
|
|
21
|
-
|
33
|
+
You can use the `JapanPostcoder` class to get the address of a location in Japan in **string** format.
|
34
|
+
```ruby
|
35
|
+
require 'japan-postcoder'
|
22
36
|
|
23
|
-
|
37
|
+
postcode = '2140037'
|
38
|
+
address = JapanPostcoder.to_address(postcode)
|
24
39
|
|
25
|
-
|
40
|
+
puts address # => "η₯ε₯ε·ηε·ε΄εΈε€ζ©εΊθ
δ»θ°·ηΊ"
|
41
|
+
```
|
26
42
|
|
27
|
-
|
43
|
+
You can also use the `JapanPostcoder` class to get the address of a location in Japan in **hash** format.
|
44
|
+
```ruby
|
45
|
+
require 'japan-postcoder'
|
28
46
|
|
29
|
-
|
47
|
+
postcode = '2140037'
|
48
|
+
address = JapanPostcoder.to_address_hash(postcode)
|
30
49
|
|
31
|
-
|
50
|
+
puts address # => {:prefecture=>"η₯ε₯ε·η", :city=>"ε·ε΄εΈ", :ward=>"ε€ζ©εΊ", :district=>"θ
δ»θ°·ηΊ"}
|
51
|
+
```
|
32
52
|
|
33
|
-
##
|
53
|
+
## π¬π§ Romaji transcription
|
34
54
|
|
35
|
-
|
55
|
+
You can use the `JapanPostcoder` class to get the address of a location in Japan in **romaji** format by using the `romaji` named argument.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
address = JapanPostcoder.to_address('2140037', romaji: true)
|
59
|
+
puts address # => "KANAGAWA KEN KAWASAKI SHI TAMA KU SUGESEN YACHO"
|
60
|
+
```
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
address = JapanPostcoder.to_address_hash('2140037', romaji: true)
|
64
|
+
puts address # => {:prefecture=>"KANAGAWA KEN", :city=>"KAWASAKI SHI", :ward=>"TAMA KU", :district=>"SUGESEN YACHO"}
|
65
|
+
```
|
66
|
+
|
67
|
+
# πͺ Contributing
|
68
|
+
|
69
|
+
If you notice a bug or want to add a new feature, please open an issue or submit a pull request.
|
70
|
+
Thank you and enjoy!
|
71
|
+
|
72
|
+
# π License
|
73
|
+
|
74
|
+
This project is free to use under the terms of the MIT License.
|
75
|
+
|
76
|
+
# π Self-memo
|
77
|
+
After updating the gem:
|
78
|
+
- Update the version in `lib/japan_postcoder/version.rb`
|
79
|
+
- Create a PR and merge it after it's been approved & tested
|
80
|
+
- Run `gem build japan_postcoder.gemspec`
|
81
|
+
- Run `gem push japan_postcoder-<version>.gem`
|
82
|
+
- Run `gh release create <version>`
|
data/japan_postcoder.gemspec
CHANGED
@@ -10,17 +10,16 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = 'π‘ A Ruby gem for getting Japan address from postal code.'
|
12
12
|
spec.description = "π―π΅ JapanPostcoder is a Ruby gem for getting Japan address from postal code.
|
13
|
-
Information is based on the data from the JapanPost website:https://www.post.japanpost.jp/zipcode/download.html.
|
13
|
+
Information is based on the data from the JapanPost website: https://www.post.japanpost.jp/zipcode/download.html.
|
14
14
|
"
|
15
15
|
spec.homepage = 'https://github.com/tonystrawberry/japan_postcoder'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
spec.required_ruby_version = '>= 2.7.0'
|
18
18
|
|
19
|
-
spec.metadata['allowed_push_host'] =
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
20
20
|
|
21
21
|
spec.metadata['homepage_uri'] = spec.homepage
|
22
22
|
spec.metadata['source_code_uri'] = 'https://github.com/tonystrawberry/japan_postcoder'
|
23
|
-
spec.metadata['changelog_uri'] = 'https://github.com/tonystrawberry/japan_postcoder/CHANGELOG.md'
|
24
23
|
|
25
24
|
# Specify which files should be added to the gem when it is released.
|
26
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -1,37 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
##
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module JapanPostcoder
|
4
|
+
## Class for Japanese Address
|
5
|
+
## Has attributes for postcode, prefecture, city, ward and district
|
6
|
+
#
|
7
|
+
class Address
|
8
|
+
attr_accessor :postcode, :prefecture, :city, :ward, :district
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
# Initialize the address with postcode, prefecture, city, ward and district
|
11
|
+
def initialize(postcode, prefecture, city, ward, district)
|
12
|
+
@postcode = postcode
|
13
|
+
@prefecture = prefecture
|
14
|
+
@city = city
|
15
|
+
@ward = ward
|
16
|
+
@district = district
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
# Returns the full address as a string
|
20
|
+
def to_s(romaji: false)
|
21
|
+
if romaji
|
22
|
+
"#{@prefecture} #{@city} #{@ward} #{@district}"
|
23
|
+
else
|
24
|
+
"#{@prefecture}#{@city}#{@ward}#{@district}"
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# Returns the full address as a hash
|
29
|
+
def to_h
|
30
|
+
{
|
31
|
+
postcode: @postcode,
|
32
|
+
prefecture: @prefecture,
|
33
|
+
city: @city,
|
34
|
+
ward: @ward,
|
35
|
+
district: @district
|
36
|
+
}
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/japan_postcoder.rb
CHANGED
@@ -14,6 +14,8 @@ module JapanPostcoder
|
|
14
14
|
# Returns the address in string format
|
15
15
|
# Example: 'η₯ε₯ε·ηε·ε΄εΈε€ζ©εΊθ₯Ώηη°'
|
16
16
|
def self.to_address(postal_code, romaji: false)
|
17
|
+
postal_code = postal_code.to_s
|
18
|
+
|
17
19
|
validate_postal_code!(postal_code)
|
18
20
|
|
19
21
|
address = get_address(postal_code, romaji: romaji)
|
@@ -31,6 +33,8 @@ module JapanPostcoder
|
|
31
33
|
# district: 'θ₯Ώηη°'
|
32
34
|
# }
|
33
35
|
def self.to_address_hash(postal_code, romaji: false)
|
36
|
+
postal_code = postal_code.to_s
|
37
|
+
|
34
38
|
validate_postal_code!(postal_code)
|
35
39
|
|
36
40
|
address = get_address(postal_code, romaji: romaji)
|
@@ -38,8 +42,6 @@ module JapanPostcoder
|
|
38
42
|
address.to_h
|
39
43
|
end
|
40
44
|
|
41
|
-
private
|
42
|
-
|
43
45
|
# Validates the postal code format
|
44
46
|
# Raises InvalidPostalCodeError if the postal code is invalid
|
45
47
|
def self.validate_postal_code!(postal_code)
|
@@ -51,7 +53,11 @@ module JapanPostcoder
|
|
51
53
|
|
52
54
|
# Returns an Address object
|
53
55
|
# Example:
|
54
|
-
# #<Japan::Address:0x00007f9d0a8d3d88 @postcode="2140037",
|
56
|
+
# #<Japan::Address:0x00007f9d0a8d3d88 @postcode="2140037",
|
57
|
+
# @prefecture="η₯ε₯ε·η",
|
58
|
+
# @city="ε·ε΄εΈ",
|
59
|
+
# @ward="ε€ζ©εΊ",
|
60
|
+
# @district="θ₯Ώηη°">
|
55
61
|
def self.get_address(postal_code, romaji: false)
|
56
62
|
# Read from ./jp_postcodes.json (Shift JIS)
|
57
63
|
# Format: {
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: japan_postcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Duong
|
@@ -12,7 +12,7 @@ date: 2023-08-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: "\U0001F1EF\U0001F1F5 JapanPostcoder is a Ruby gem for getting Japan
|
14
14
|
address from postal code.\n Information is based on the data from the JapanPost
|
15
|
-
website:https://www.post.japanpost.jp/zipcode/download.html.\n "
|
15
|
+
website: https://www.post.japanpost.jp/zipcode/download.html.\n "
|
16
16
|
email:
|
17
17
|
- tony.duong.102@gmail.com
|
18
18
|
executables: []
|
@@ -21,12 +21,9 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- ".rspec"
|
23
23
|
- ".rubocop.yml"
|
24
|
-
- CHANGELOG.md
|
25
24
|
- LICENSE.txt
|
26
25
|
- README.md
|
27
26
|
- Rakefile
|
28
|
-
- japan_postcoder-0.1.0.gem
|
29
|
-
- japan_postcoder-0.1.1.gem
|
30
27
|
- japan_postcoder.gemspec
|
31
28
|
- lib/japan_postcoder.rb
|
32
29
|
- lib/japan_postcoder/address.rb
|
@@ -36,10 +33,9 @@ homepage: https://github.com/tonystrawberry/japan_postcoder
|
|
36
33
|
licenses:
|
37
34
|
- MIT
|
38
35
|
metadata:
|
39
|
-
allowed_push_host: https://rubygems.org
|
36
|
+
allowed_push_host: https://rubygems.org/
|
40
37
|
homepage_uri: https://github.com/tonystrawberry/japan_postcoder
|
41
38
|
source_code_uri: https://github.com/tonystrawberry/japan_postcoder
|
42
|
-
changelog_uri: https://github.com/tonystrawberry/japan_postcoder/CHANGELOG.md
|
43
39
|
rubygems_mfa_required: 'true'
|
44
40
|
post_install_message:
|
45
41
|
rdoc_options: []
|
data/CHANGELOG.md
DELETED
data/japan_postcoder-0.1.0.gem
DELETED
Binary file
|
data/japan_postcoder-0.1.1.gem
DELETED
Binary file
|