Class: EanCountry

Inherits:
Object
  • Object
show all
Defined in:
lib/ean-country.rb

Class Method Summary collapse

Class Method Details

.infer(code) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ean-country.rb', line 4

def self.infer(code)
  # insurance
  code = code.to_s

  countries = {
    "380" => "BG",
    "383" => "SI",
    "385" => "HR",
    "387" => "BA",
    "45" => "JP",
    "46" => "RU",
    "49" => "JP",
    "471" => "TW",
    "474" => "EE",
    "475" => "LV",
    "477" => "LT",
    "479" => "LK",
    "480" => "PH",
    "482" => "UA",
    "484" => "MD",
    "485" => "AM",
    "486" => "GE",
    "487" => "KZ",
    "489" => "KH",
    "50" => "GB",
    "520" => "GR",
    "528" => "LB",
    "529" => "CY",
    "531" => "MK",
    "535" => "MT",
    "539" => "IE",
    "54" => "BE", #known bug - also LU
    "560" => "PT",
    "569" => "IS",
    "57" => "DK",
    "590" => "PL",
    "594" => "RO",
    "599" => "HU",
    "600" => "ZA",
    "601" => "ZA",
    "609" => "MU",
    "611" => "MA",
    "613" => "DZ",
    "619" => "TN",
    "622" => "EG",
    "626" => "IR",
    "64" => "FI",
    "690" => "CN",
    "691" => "CN",
    "70" => "NO",
    "729" => "IL",
    "73" => "SE",
    "740" => "GT",
    "741" => "SV",
    "742" => "HN",
    "743" => "NI",
    "744" => "CR",
    "745" => "PA",
    "746" => "DM",
    "750" => "MX",
    "759" => "VE",
    "76" => "CH",
    "770" => "CO",
    "773" => "UY",
    "775" => "PE",
    "777" => "BO",
    "779" => "AR",
    "780" => "CL",
    "784" => "PY",
    "786" => "EC",
    "789" => "BR",
    "80" => "IT",
    "81" => "IT",
    "82" => "IT",
    "83" => "IT",
    "84" => "ES",
    "850" => "CU",
    "858" => "SK",
    "859" => "CZ",
    "860" => nil, # Yugoslavia no longer exists - no idea how to roll this one
    "869" => "TR",
    "87" => "NL",
    "880" => "KR",
    "885" => "TH",
    "888" => "SG",
    "890" => "IN",
    "893" => "VN",
    "899" => "ID",
    "90" => "AT",
    "91" => "AT",
    "93" => "AU",
    "94" => "NZ",
    "955" => "MY" }

  # 01 to 09: US
  if code[0] == "0"
    return "US"
  end

  toin = code[0..2].to_i

  # 400, 401, 402... to 440: DE - special case
  if(toin >= 400 and toin <= 440)
    return "DE"
  end

  toin = code[0..1].to_i

  # 30-37: FR
  if(toin >= 30 and toin <= 37)
    return "FR"
  end

  two = code[0..1]

  if countries.has_key?(two)
    return countries[two]
  end

  three = code[0..2]

  if countries.has_key?(three)
    return countries[three]
  end

  return nil
end