Sha256: cc712733225defe6f5bb5eb30b7ceb5ac1790da90e5f67b6cde2a99b21d6a60c

Contents?: true

Size: 585 Bytes

Versions: 7

Compression:

Stored size: 585 Bytes

Contents

# coding: utf-8
require 'yaml'

module JpPrefecture
  # コードと郵便番号のマッピング
  module ZipMapping

    filepath = File.join(File.dirname(__FILE__), '../../data/zip.yml')
    @data = YAML.load_file(filepath)
    @data = Hash[*@data.collect{|code, arr|[code, arr.collect{|zip_from, zip_to|zip_from..zip_to}]}.flatten(1)]

    def self.data
      JpPrefecture.config.zip_mapping_data || @data
    end

    def self.code_for_zip zip
      self.data.select do |code, zip_ranges|
        zip_ranges.find{|range|range.include? zip}
      end.keys.first
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jp_prefecture-0.11.0 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.10.0 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.9.0 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.8.1 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.8.0 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.7.0 lib/jp_prefecture/zip_mapping.rb
jp_prefecture-0.6.0 lib/jp_prefecture/zip_mapping.rb