dialable 0.6.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,5 @@
1
1
  $LOAD_PATH.push File.join(File.dirname(__FILE__), '..', 'lib')
2
2
 
3
- require "rubygems"
4
- require "dialable"
3
+ require 'rubygems'
4
+ require 'dialable'
5
5
 
6
- RSpec.configure do |config|
7
- end
@@ -1,34 +1,134 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "csv"
4
- require "fileutils"
5
- require "yaml"
3
+ require 'csv'
4
+ require 'yaml'
6
5
 
7
- system('wget --quiet "http://nanpa.com/npa/AllNPAs.zip"')
8
- system('unzip -qj AllNPAs.zip AllNPAs.mdb')
9
- system('mdb-export AllNPAs.mdb "`mdb-tables -1 AllNPAs.mdb`" > AllNPAs.csv')
6
+ # Headers from http://nanpa.com/area_codes/AreaCodeDatabaseDefinitions.xls
7
+ headers = [:npa, :type_of_code, :assignable, :explanation, :reserved, :assigned, :asgt_date, :use, :location, :country, :in_service, :in_svc_date, :status, :pl, :blank, :overlay, :overlay_complex, :parent, :service, :time_zone, :blank, :map, :is_npa_in_jeopardy, :is_relief_planning_in_progress, :home_npa_local_calls, :home_npa_toll_calls, :foreign_npa_local_calls, :foreign_npa_toll_calls, :perm_hnpa_local, :perm_hnpa_toll, :perm_fnpa_local, :dp_notes]
10
8
 
11
- all = CSV.read("AllNPAs.csv")
12
- h = all[0]
9
+ nanpa = { :created => Time.now }
13
10
 
14
- in_service = h.index("In Service?")
15
- location = h.index("Location")
16
- country = h.index("Country")
17
- tz = h.index("Time Zone")
18
- npa = h.index("NPA")
11
+ curl = `curl -sL http://nanpa.com/nanp1/npa_report.csv`
19
12
 
20
- nanpa = { :created => Time.now }
13
+ CSV.parse(curl, :headers => headers) do |row|
14
+ next unless row.fetch(:npa) =~ /\A\d+\Z/ && row.fetch(:in_service).to_s =~ /y/i
15
+ npa = row[:npa].to_i
16
+ country = row.fetch(:country)
17
+ location = row.fetch(:location) { 'US' }
18
+ location = 'US' if location =~ /NANP Area/i || location =~ /\A#{country}\Z/i
21
19
 
22
- all.each do |row|
23
- next unless row[in_service] == "Yes"
24
- areacode = row[npa].to_s.to_i
25
- nanpa[areacode] = {}
26
- nanpa[areacode][:country] = row[country].to_s if row[country].to_s.size > 0
27
- nanpa[areacode][:timezone] = row[tz].to_s if row[tz].to_s.size > 0
28
- nanpa[areacode][:location] = row[location].to_s if row[location].to_s.size > 0 and row[location].to_s !~ /NANP Area/i and row[location].to_s !~ /^#{row[country].to_s}$/i
20
+ raw_timezones = row.fetch(:time_zone) { '' }.to_s.gsub(/[\(\)]/, '')
21
+ timezones = []
22
+ if raw_timezones =~ /UTC([\+\-]\d+)/
23
+ timezones << case Regexp.last_match(1).to_i
24
+ when 10
25
+ 'Pacific/Guam'
26
+ when -10
27
+ 'US/Hawaii'
28
+ when -9
29
+ 'US/Alaska'
30
+ end
31
+ elsif country && country.upcase == "CANADA"
32
+ if raw_timezones.split(//).any?
33
+ timezones << raw_timezones.split(//).collect do |timezone|
34
+ case timezone
35
+ when 'E'
36
+ "Canada/Eastern"
37
+ when 'C'
38
+ "Canada/Central"
39
+ when 'M'
40
+ "Canada/Mountain"
41
+ when 'P'
42
+ "Canada/Pacific"
43
+ when 'N'
44
+ "Canada/Newfoundland"
45
+ when 'A'
46
+ "Canada/Atlantic"
47
+ else
48
+ 'America/None'
49
+ end
50
+ end
51
+ else
52
+ timezones << case location
53
+ when 'ONTARIO'
54
+ "Canada/Eastern"
55
+ when 'MANITOBA'
56
+ "Canada/Central"
57
+ when 'QUEBEC'
58
+ "Canada/Eastern"
59
+ else
60
+ 'America/None'
61
+ end
62
+ end
63
+ elsif country && country.upcase == "US"
64
+ timezones << raw_timezones.split(//).collect do |timezone|
65
+ case timezone
66
+ when 'E'
67
+ "US/Eastern"
68
+ when 'C'
69
+ "US/Central"
70
+ when 'M'
71
+ "US/Mountain"
72
+ when 'P'
73
+ "US/Pacific"
74
+ else
75
+ case location
76
+ when 'USVI'
77
+ "America/Virgin"
78
+ when 'PUERTO RICO'
79
+ "America/Puerto_Rico"
80
+ when 'AS'
81
+ nil
82
+ else
83
+ 'America/None'
84
+ end
85
+ end
86
+ end
87
+ elsif country
88
+ timezones << case country.upcase
89
+ when "BAHAMAS"
90
+ "America/Virgin"
91
+ when "BARBADOS"
92
+ "America/Barbados"
93
+ when "ANGUILLA"
94
+ "America/Anguilla"
95
+ when "ANTIGUA/BARBUDA"
96
+ "America/Antigua"
97
+ when "BERMUDA"
98
+ "Atlantic/Bermuda"
99
+ when "BRITISH VIRGIN ISLANDS"
100
+ "America/Virgin"
101
+ when "CAYMAN ISLANDS"
102
+ "America/Cayman"
103
+ when "GRENADA"
104
+ "America/Grenada"
105
+ when "TURKS & CAICOS ISLANDS"
106
+ "America/Virgin"
107
+ when "MONTSERRAT"
108
+ "America/Montserrat"
109
+ when "SINT MAARTEN"
110
+ "America/Virgin"
111
+ when "ST. LUCIA"
112
+ "America/St_Lucia"
113
+ when "DOMINICA"
114
+ "America/Dominica"
115
+ when "ST. VINCENT & GRENADINES"
116
+ "America/Virgin"
117
+ when "DOMINICAN REPUBLIC"
118
+ "America/Virgin"
119
+ when "TRINIDAD AND TOBAGO"
120
+ "America/Virgin"
121
+ when "ST. KITTS AND NEVIS"
122
+ "America/Virgin"
123
+ when "JAMAICA"
124
+ "America/Jamaica"
125
+ end
126
+ end
127
+
128
+ nanpa[npa] = { :country => country }
129
+ nanpa[npa][:timezones] = timezones.flatten.compact if timezones && timezones.flatten.compact.size > 0
130
+ nanpa[npa][:location] = location if location
29
131
  end
30
132
 
31
133
  puts nanpa.to_yaml
32
134
 
33
- FileUtils.rm ["AllNPAs.zip", "AllNPAs.mdb", "AllNPAs.csv"]
34
-
metadata CHANGED
@@ -1,71 +1,183 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dialable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - chorn
7
+ - Chris Horn
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2013-11-12 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIJvjCCBaagAwIBAgIJAM/4MvGHp6qBMA0GCSqGSIb3DQEBDQUAMDoxHjAcBgkq
14
+ hkiG9w0BCQEWD2Nob3JuQGNob3JuLmNvbTEYMBYGA1UEAwwPY2hvcm5AY2hvcm4u
15
+ Y29tMB4XDTE1MDYxOTExMzIyNVoXDTIwMDYxNzExMzIyNVowOjEeMBwGCSqGSIb3
16
+ DQEJARYPY2hvcm5AY2hvcm4uY29tMRgwFgYDVQQDDA9jaG9ybkBjaG9ybi5jb20w
17
+ ggQiMA0GCSqGSIb3DQEBAQUAA4IEDwAwggQKAoIEAQCrmvCKjihyb0/wGp6xds1M
18
+ PII8KrtYztDRFD5kmJioqBt/8VcjrLqgCPKzafCY/ztLoRq7Zegjeer/QS7mUJGL
19
+ EIG8hMSsA80y1+jCa0TmIbpRic9Y5RQoA0SiKGBqZ1j0rbhP5ZbQXxE6IG9aSxRU
20
+ WTeSiGfcxWOG+as0L1qBrpuS9wXGenwsudLNouCY0ekRhOyQr3g+9U/dJqkb5ucg
21
+ Mj9OyYQFPLnbml4SoTVy7KcbuuzEyPcaf+Zc688if5Bc3yQddnQfmbINhuQuqk/f
22
+ EXOFarN1jZLN04mqjOYa9vR0W+AxEtrYLaTD1+ILoJzFhlO5NCTBMxSVNxlt95sY
23
+ opEabhgZolrUA653mnAvNq7HEnbdH4iSUEHtSD1e0goGhaRmh7NmJPR3jQgj4dox
24
+ L+FlE2MF4SW0lP74438BO29ClenGnPNgYWFuV0rSjmyTIMKkFHYP43VsNGVUv3zh
25
+ JH6uqkXQvjEPWYqC42noEmpga1xxRKUizj90gzFtBXtOYi2AX2/RvpiPI2wabFoC
26
+ s2QByquD0f8oXj60e1MLDXm7i0qImCLzzWyjXqTmM+7pdRBFYOmD4MiOKViZsdfs
27
+ fTfv+bJx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U59ydjqtevg9cZIco0tiTzGrBrcy7xnVWQKt+hbsV702V02Nx7gG4ihLRMIdAjtL
59
+ nnnm3d3shuIrTfRG4YwBiYdJlT0X92geAtQbq5OPrT/27DBV6h3YydBoozkVEaZp
60
+ Bvbz27URCmOw2e4psQctUBuVrTPirjqEwOql/SqqJsMIdWQ6oXLy235iuGzDgx+p
61
+ Fi8s5azIOjbjFnc4OBols94L3oZxyIf+lUXgNBcvQ1wbWBlo+V1hyRWLSvLPLAtr
62
+ 3eeuQZ5HTqTSZSaMKfFrH10hG06h7Zla7oYxSn0GJsgu/aI1STGFHenjNeNRyFb4
63
+ Qcofa1uD1LTI/r7EKL1I25n6eiABGw0KNDvow/ZtP9Kmx2QobEsWUbPfvkX1ogdj
64
+ plBjPb1jywhCxKfdcYv+f4er+X1AnUyoYNi7EiifiNys7nmVG4+aFEZyUULPrB2g
65
+ bHE=
66
+ -----END CERTIFICATE-----
67
+ date: 2015-12-08 00:00:00.000000000 Z
12
68
  dependencies:
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: tzinfo
15
71
  requirement: !ruby/object:Gem::Requirement
16
72
  requirements:
17
- - - '>='
73
+ - - "~>"
18
74
  - !ruby/object:Gem::Version
19
- version: '0'
75
+ version: '1.0'
20
76
  type: :runtime
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
- - - '>='
80
+ - - "~>"
25
81
  - !ruby/object:Gem::Version
26
- version: '0'
82
+ version: '1.0'
27
83
  - !ruby/object:Gem::Dependency
28
- name: rake
84
+ name: bundler
29
85
  requirement: !ruby/object:Gem::Requirement
30
86
  requirements:
31
- - - '>='
87
+ - - "~>"
32
88
  - !ruby/object:Gem::Version
33
- version: '0'
89
+ version: '1.6'
34
90
  type: :development
35
91
  prerelease: false
36
92
  version_requirements: !ruby/object:Gem::Requirement
37
93
  requirements:
38
- - - '>='
94
+ - - "~>"
39
95
  - !ruby/object:Gem::Version
40
- version: '0'
96
+ version: '1.6'
41
97
  - !ruby/object:Gem::Dependency
42
- name: rspec
98
+ name: codeclimate-test-reporter
43
99
  requirement: !ruby/object:Gem::Requirement
44
100
  requirements:
45
- - - '>='
101
+ - - "~>"
46
102
  - !ruby/object:Gem::Version
47
- version: '0'
103
+ version: '0.4'
48
104
  type: :development
49
105
  prerelease: false
50
106
  version_requirements: !ruby/object:Gem::Requirement
51
107
  requirements:
52
- - - '>='
108
+ - - "~>"
53
109
  - !ruby/object:Gem::Version
54
- version: '0'
110
+ version: '0.4'
55
111
  - !ruby/object:Gem::Dependency
56
- name: tzinfo
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '10.4'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '10.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
57
169
  requirement: !ruby/object:Gem::Requirement
58
170
  requirements:
59
- - - '>='
171
+ - - "~>"
60
172
  - !ruby/object:Gem::Version
61
- version: '0'
173
+ version: '3.3'
62
174
  type: :development
63
175
  prerelease: false
64
176
  version_requirements: !ruby/object:Gem::Requirement
65
177
  requirements:
66
- - - '>='
178
+ - - "~>"
67
179
  - !ruby/object:Gem::Version
68
- version: '0'
180
+ version: '3.3'
69
181
  description: A gem that provides parsing and output of phone numbers according to
70
182
  NANPA (North American Numbering Plan Administration) standards. If possible, time
71
183
  zones are populated by abbreviation as well as offset relative to the local timezone.
@@ -75,18 +187,22 @@ executables: []
75
187
  extensions: []
76
188
  extra_rdoc_files: []
77
189
  files:
78
- - .gitignore
79
- - .travis.yml
190
+ - ".gitignore"
191
+ - ".travis.yml"
80
192
  - Gemfile
81
193
  - Gemfile.lock
194
+ - Guardfile
82
195
  - LICENSE
83
- - README.rdoc
196
+ - README.md
84
197
  - Rakefile
85
- - TODO
198
+ - certs/chorn.pem
86
199
  - data/dialable/nanpa.yaml
87
- - data/nanpa.yaml
88
200
  - dialable.gemspec
89
201
  - lib/dialable.rb
202
+ - lib/dialable/area_codes.rb
203
+ - lib/dialable/parsers.rb
204
+ - lib/dialable/patterns.rb
205
+ - lib/dialable/service_codes.rb
90
206
  - lib/dialable/version.rb
91
207
  - spec/dialable_spec.rb
92
208
  - spec/spec.opts
@@ -103,17 +219,17 @@ require_paths:
103
219
  - lib
104
220
  required_ruby_version: !ruby/object:Gem::Requirement
105
221
  requirements:
106
- - - '>='
222
+ - - ">="
107
223
  - !ruby/object:Gem::Version
108
224
  version: 1.9.0
109
225
  required_rubygems_version: !ruby/object:Gem::Requirement
110
226
  requirements:
111
- - - '>='
227
+ - - ">="
112
228
  - !ruby/object:Gem::Version
113
229
  version: '0'
114
230
  requirements: []
115
231
  rubyforge_project:
116
- rubygems_version: 2.1.10
232
+ rubygems_version: 2.4.5.1
117
233
  signing_key:
118
234
  specification_version: 4
119
235
  summary: Provides parsing and output of phone numbers according to NANPA standards.
Binary file
@@ -1,45 +0,0 @@
1
- == dialable
2
- {<img src="https://badge.fury.io/rb/dialable.png" alt="Gem Version" />}[http://badge.fury.io/rb/dialable]
3
- {<img src="https://travis-ci.org/chorn/dialable.png" />}[https://travis-ci.org/chorn/dialable]
4
-
5
- A gem that provides parsing and output of phone numbers according to NANPA standards.
6
-
7
-
8
- Phone numbers are not a big deal if you can validate the input at the
9
- time you've got a human right there. My enterprise tends not to have
10
- that ability, as we receive large files from clients with little or no
11
- validation done. Rather than abandon #s which don't validate, I wrote
12
- this to parse and normalize a string into a standard NANP phone
13
- number, possibly including an extension.
14
-
15
- References: NANPA: North American Numbering Plan Administration http://nanpa.com/
16
-
17
- The YAML file with the valid area codes and easily recognizable codes
18
- (like 911) can get out of date. To update your own copy, run:
19
-
20
- support/make_yaml_nanpa.rb > data/nanpa.yaml
21
-
22
-
23
- require "dialable"
24
-
25
- pn = Dialable::NANP.parse("+1(800)555-1212 ext 1234")
26
-
27
- >> puts pn.to_s // Pretty output
28
-
29
- 800-555-1212 x1234
30
-
31
- >> puts pn.to_digits // Address book friendly
32
-
33
- 8005551212 x1234
34
-
35
- >> puts pn.to_dialable // PBX friendly
36
-
37
- 8005551212
38
-
39
- >> puts pn.extension
40
-
41
- 1234
42
-
43
- Also, pn.timezones and pn.relative_timezones should do the right thing.
44
-
45
- -chorn