Module: PostalCheck

Defined in:
lib/postal_check.rb,
lib/postal_check/version.rb

Constant Summary collapse

POSTAL_PATH =
"#{File.dirname(__FILE__)}/postal_check".freeze
VERSION =
"0.1.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check(city_code, postal_code) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Method Details

#cd_check(city_code) ⇒ Object



71
72
73
74
# File 'lib/postal_check.rb', line 71

def cd_check(city_code)
  return false if city_code==''
  true
end