module PostalCheck

Constants

POSTAL_PATH
VERSION

Public Class Methods

check(city_code, postal_code) click to toggle source
# File lib/postal_check.rb, line 35
def self.check(city_code, postal_code)
  path = "#{POSTAL_PATH}/postal.csv"

  postals_array = CSV.read(path).select { |postal| postal[1] == postal_code }
  postals_array.map do |postal_param|
    {
      city_code:    postal_param[0],
      postal_code:  postal_param[1],
      prefecture: postal_param[2],
      city:       postal_param[3]
    }
  end



  # "[\"13107\", \"130-0015\", \"東京都\", \"墨田区\"]"
  target_data = postals_array.at(0)
  return false if target_data.blank?

  if city_code.instance_of?(Array)
    city_code.each do |cd|
      if cd.to_s == target_data.at(0)
        return true
      end
    end
    return false
  end

  if city_code.to_s == target_data.at(0)
    return true
  else
    "#{target_data.at(0)}"
    return false
  end
end
city_code(city_code) click to toggle source
# File lib/postal_check.rb, line 7
def self.city_code(city_code)
  path = "#{POSTAL_PATH}/postal.csv"

  postals_array = CSV.read(path).select { |postal| postal[0] == city_code }
  postals_array.map do |postal_param|
    {
      city_code:    postal_param[0],
      postal_code:  postal_param[1],
      prefecture: postal_param[2],
      city:       postal_param[3]
    }
  end
end
postal_code(postal_code) click to toggle source
# File lib/postal_check.rb, line 21
def self.postal_code(postal_code)
  path = "#{POSTAL_PATH}/postal.csv"

  postals_array = CSV.read(path).select { |postal| postal[1] == postal_code }
  postals_array.map do |postal_param|
    {
      city_code:    postal_param[0],
      postal_code:  postal_param[1],
      prefecture: postal_param[2],
      city:       postal_param[3]
    }
  end
end

Public Instance Methods

cd_check(city_code) click to toggle source
# File lib/postal_check.rb, line 71
def cd_check(city_code)
  return false if city_code==''
  true
end