Skip to content

Commit

Permalink
Merge pull request #8 from ToUMenu/peter/improve
Browse files Browse the repository at this point in the history
Improve Address Method
  • Loading branch information
PeterTeng committed Mar 7, 2019
2 parents db8e918 + 693b388 commit d0cd0b5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sudo: false
language: ruby
cache: bundler
rvm:
- 2.0.0
- 2.1.0
- 2.2.2
- 2.2.5
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
[![Build Status](https://travis-ci.org/ToUMenu/taiwan-address.svg?branch=master)](https://travis-ci.org/ToUMenu/taiwan-address)
[![Coverage Status](https://coveralls.io/repos/github/ToUMenu/taiwan-address/badge.svg?branch=master)](https://coveralls.io/github/ToUMenu/taiwan-address?branch=master)


Taiwan Address. Supports Traditional Chinese, Japanese, English.

## Installation

Install with application's Gemfile:
Expand Down
16 changes: 14 additions & 2 deletions lib/taiwan_address/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def district
return I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: @locale) unless [300, 600].include?(@code)
end

def address
def address(delimiter=" ", order_reverse=false)
if [300, 600].include?(@code)
return self.zone
else
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: @locale)
return "#{self.zone} #{district}"

if order_reverse
return "#{district}#{resolve_delimiter(delimiter)}#{self.zone}"
end
return "#{self.zone}#{resolve_delimiter(delimiter)}#{district}"
end
end

Expand Down Expand Up @@ -103,5 +107,13 @@ def is_islands?
district = I18n.t("districts.#{PostalCode::POSTAL_CODE_HASH[@code]}", locale: :en)
return district.end_with?("Islands")
end

private
def resolve_delimiter(delimiter)
if delimiter == ","
return ", "
end
return delimiter
end
end
end
2 changes: 1 addition & 1 deletion lib/taiwan_address/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TaiwanAddress
VERSION = "0.3.0"
VERSION = "0.3.1"
end
5 changes: 5 additions & 0 deletions spec/taiwan_address/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

it 'should return address' do
expect(instance.address).to eq "Taipei City Da An District"
expect(instance.address(delimiter=",")).to eq "Taipei City, Da An District"
expect(instance.address(delimiter=" ", order_reverse=true)).to eq "Da An District Taipei City"
expect(instance.address(delimiter=",", order_reverse=true)).to eq "Da An District, Taipei City"
end

it 'should return zone with zh-TW' do
Expand All @@ -31,6 +34,7 @@
it 'should return address with zh-TW' do
instance.locale = :"zh-TW"
expect(instance.address).to eq "台北市 大安區"
expect(instance.address(delimiter="")).to eq "台北市大安區"
end

it 'should return zone with ja' do
Expand All @@ -46,6 +50,7 @@
it 'should return address with ja' do
instance.locale = :ja
expect(instance.address).to eq "台北市 大安区"
expect(instance.address(delimiter="")).to eq "台北市大安区"
end
end

Expand Down

0 comments on commit d0cd0b5

Please sign in to comment.