Skip to content

Commit

Permalink
Merge pull request #102 from yamat47/fix-read-full_address
Browse files Browse the repository at this point in the history
`#full_address`が処理前の住所の一部のみを返すようになっていた不具合を解消した。
  • Loading branch information
yamat47 authored Nov 26, 2023
2 parents b9350dd + 1dd13f0 commit eee3b7f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Metrics/BlockLength:
RSpec/ContextWording:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

# MITなのでファイルの著作権は記載しない。
Style/Copyright:
Enabled: false
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Change Log の形式は [Keep a Changelog](http://keepachangelog.com/) に従い

### Removed

- [#102](https://github.com/yamat47/japanese_address_parser/pull/102) #full_addressが処理前の住所の一部のみを返すようになっていた不具合を解消した。([@yamat47](https://github.com/yamat47))

### Fixed

### Security
Expand Down
2 changes: 1 addition & 1 deletion lib/japanese_address_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _call(full_address)

# このライブラリで探索するのは町域まで。
# それ以降のデータを使って探索するとデータと名前が一致しないことがあるので、町域までのデータを使う。
::JapaneseAddressParser::AddressParser.call("#{normalized['pref']}#{normalized['city']}#{normalized['town']}")
::JapaneseAddressParser::AddressParser.call(normalized: "#{normalized['pref']}#{normalized['city']}#{normalized['town']}", full_address: full_address)
end

module_function :call, :call!, :_call
Expand Down
6 changes: 3 additions & 3 deletions lib/japanese_address_parser/address_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

module JapaneseAddressParser
module AddressParser
def call(full_address)
prefecture = ::JapaneseAddressParser::Models::Prefecture.all.find { |candidate| full_address.start_with?(candidate.name) }
def call(normalized:, full_address:)
prefecture = ::JapaneseAddressParser::Models::Prefecture.all.find { |candidate| normalized.start_with?(candidate.name) }

return _build_address(full_address: full_address) if prefecture.nil?

city_and_after = full_address.delete_prefix(prefecture.name)
city_and_after = normalized.delete_prefix(prefecture.name)
city = prefecture.cities.find { |candidate| city_and_after.start_with?(candidate.name) }

return _build_address(full_address: full_address, prefecture: prefecture) if city.nil?
Expand Down
2 changes: 1 addition & 1 deletion sig/japanese_address_parser.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module JapaneseAddressParser
end

module AddressParser
def self.call: (String full_address) -> Models::Address
def self.call: (normalized: String, full_address: String) -> Models::Address
end

module Models
Expand Down
8 changes: 8 additions & 0 deletions spec/japanese_address_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq('東京都北区'))
expect(parsed_address.furigana).to(eq('トウキョウトキタク'))
end
end
Expand All @@ -25,6 +26,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_nil)
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand All @@ -39,6 +41,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand All @@ -53,6 +56,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_a(::JapaneseAddressParser::Models::Town))
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand All @@ -78,6 +82,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq('東京都北区'))
expect(parsed_address.furigana).to(eq('トウキョウトキタク'))
end
end
Expand All @@ -91,6 +96,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_nil)
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand All @@ -105,6 +111,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_nil)
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand All @@ -119,6 +126,7 @@
expect(parsed_address.prefecture).to(be_a(::JapaneseAddressParser::Models::Prefecture))
expect(parsed_address.city).to(be_a(::JapaneseAddressParser::Models::City))
expect(parsed_address.town).to(be_a(::JapaneseAddressParser::Models::Town))
expect(parsed_address.full_address).to(eq(address['full_address']))
expect(parsed_address.furigana).to(eq(address['furigana']))
end
end
Expand Down

0 comments on commit eee3b7f

Please sign in to comment.