Sha256: 230da742c9d4c975e95a76e59ca9effa4f4565c7c91244a245fcd3d59675db9b

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'schmooze'

module JapaneseAddressParser
  module AddressNormalizer
    class NormalizeJapaneseAddressesSchmoozer < ::Schmooze::Base
      JS_PACKAGE_PATH = ::File.expand_path('../../../js', __dir__)
      public_constant :JS_PACKAGE_PATH

      JAPANESE_API_PATH = "file://#{::File.expand_path('../data/geolonia-japanese-addresses/api/ja', __dir__)}"
      public_constant :JAPANESE_API_PATH

      dependencies normalize_japanese_addresses: '@geolonia/normalize-japanese-addresses'
      method :set_japanese_api_path, 'function (path) { normalize_japanese_addresses.config.japaneseAddressesApi = path }'
      method :normalize, 'normalize_japanese_addresses.normalize'

      def self.call(full_address)
        schmoozer = new(::JapaneseAddressParser::AddressNormalizer::NormalizeJapaneseAddressesSchmoozer::JS_PACKAGE_PATH)

        # 町丁目データを取得するAPIとしてローカルにあるファイルを指定する。
        # Web APIを利用しないようにすることで処理の効率を向上する。
        # 参考: https://github.com/geolonia/normalize-japanese-addresses#configjapaneseaddressesapi-string
        schmoozer.set_japanese_api_path(::JapaneseAddressParser::AddressNormalizer::NormalizeJapaneseAddressesSchmoozer::JAPANESE_API_PATH)

        schmoozer.normalize(full_address)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
japanese_address_parser-3.0.0 lib/japanese_address_parser/address_normalizer/normalize_japanese_addresses_schmoozer.rb
japanese_address_parser-2.2.1 lib/japanese_address_parser/address_normalizer/normalize_japanese_addresses_schmoozer.rb
japanese_address_parser-2.2.0 lib/japanese_address_parser/address_normalizer/normalize_japanese_addresses_schmoozer.rb