dialable 0.5.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/README.rdoc +2 -0
- data/Rakefile +1 -37
- data/data/dialable/nanpa.yaml +1396 -0
- data/data/nanpa.yaml +371 -359
- data/dialable.gemspec +25 -24
- data/lib/dialable.rb +11 -10
- data/lib/dialable/version.rb +3 -0
- data/spec/dialable_spec.rb +10 -2
- data/spec/spec.opts +5 -0
- metadata +105 -33
data/dialable.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dialable/version'
|
5
|
+
|
6
|
+
spec = Gem::Specification.new do |gem|
|
7
|
+
gem.licenses = ['MIT', 'LGPL-2']
|
8
|
+
gem.required_ruby_version = '>= 1.9.0'
|
9
|
+
gem.name = "dialable"
|
10
|
+
gem.version = Dialable::VERSION
|
11
|
+
gem.authors = ["chorn"]
|
12
|
+
gem.email = ["chorn@chorn.com"]
|
13
|
+
gem.description = %q{A gem that provides parsing and output of phone numbers according to NANPA (North American Numbering Plan Administration) standards. If possible, time zones are populated by abbreviation as well as offset relative to the local timezone.}
|
14
|
+
gem.summary = %q{Provides parsing and output of phone numbers according to NANPA standards.}
|
15
|
+
gem.homepage = "http://github.com/chorn/dialable"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.add_dependency "tzinfo"
|
22
|
+
gem.add_development_dependency "rake"
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "tzinfo"
|
25
25
|
end
|
26
|
+
|
data/lib/dialable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Copyright (c) 2008-2011 Chris Horn http://chorn.com/
|
2
2
|
# See MIT-LICENSE.txt
|
3
3
|
|
4
|
+
require "dialable/version"
|
4
5
|
require "yaml"
|
5
6
|
require "tzinfo"
|
6
7
|
require 'rubygems'
|
@@ -45,12 +46,12 @@ module Dialable
|
|
45
46
|
# Valid area codes per nanpa.com
|
46
47
|
module AreaCodes
|
47
48
|
data_path = Gem::datadir('dialable')
|
48
|
-
data_path ||= File.join(File.dirname(__FILE__), '..', 'data')
|
49
|
-
NANP = YAML.load_file(data_path
|
49
|
+
data_path ||= File.join(File.dirname(__FILE__), '..', 'data', 'dialable')
|
50
|
+
NANP = YAML.load_file(File.join(data_path, "nanpa.yaml"))
|
50
51
|
end
|
51
|
-
|
52
|
+
|
52
53
|
attr_accessor :areacode, :prefix, :line, :extension, :location, :country, :timezones, :relative_timezones, :raw_timezone
|
53
|
-
|
54
|
+
|
54
55
|
def initialize(parts={})
|
55
56
|
self.areacode = parts[:areacode] ? parts[:areacode] : nil
|
56
57
|
self.prefix = parts[:prefix] ? parts[:prefix] : nil
|
@@ -112,7 +113,7 @@ module Dialable
|
|
112
113
|
def timezone
|
113
114
|
@timezones.first if @timezones
|
114
115
|
end
|
115
|
-
|
116
|
+
|
116
117
|
def timezone=(tz)
|
117
118
|
@timezones = [tz] if tz
|
118
119
|
end
|
@@ -120,7 +121,7 @@ module Dialable
|
|
120
121
|
# def relative_timezones
|
121
122
|
# rt = []
|
122
123
|
# @timezones.each do |tz|
|
123
|
-
# rt <<
|
124
|
+
# rt <<
|
124
125
|
# end
|
125
126
|
# rt
|
126
127
|
# end
|
@@ -129,14 +130,14 @@ module Dialable
|
|
129
130
|
Patterns::VALID.each do |pattern|
|
130
131
|
return Dialable::NANP.new(:areacode => $1, :prefix => $2, :line => $3, :extension => $4) if number =~ pattern
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
raise InvalidNANPError, "Not a valid NANP Phone Number."
|
134
135
|
end
|
135
136
|
|
136
137
|
def erc?
|
137
138
|
return ServiceCodes::ERC[@areacode].nil?
|
138
139
|
end
|
139
|
-
|
140
|
+
|
140
141
|
def to_s
|
141
142
|
rtn = "#{@prefix}-#{@line}"
|
142
143
|
rtn = "#{@areacode}-#{rtn}" if @areacode
|
@@ -156,7 +157,7 @@ module Dialable
|
|
156
157
|
rtn = "#{@areacode}#{rtn}" if @areacode
|
157
158
|
rtn
|
158
159
|
end
|
159
|
-
|
160
|
+
|
160
161
|
def to_hash
|
161
162
|
return {
|
162
163
|
:areacode => @areacode,
|
@@ -165,5 +166,5 @@ module Dialable
|
|
165
166
|
:extension => @extension
|
166
167
|
}
|
167
168
|
end
|
168
|
-
end
|
169
|
+
end
|
169
170
|
end
|
data/spec/dialable_spec.rb
CHANGED
@@ -3,12 +3,20 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe Dialable do
|
4
4
|
describe "with a full NANP number with extension" do
|
5
5
|
subject { Dialable::NANP.parse("+1(307)555-1212 ext 1234") }
|
6
|
-
|
6
|
+
|
7
7
|
it("should extract the area code") { subject.areacode.should == "307" }
|
8
8
|
it("should extract the prefix") { subject.prefix.should == "555" }
|
9
9
|
it("should extract the line number") { subject.line.should == "1212" }
|
10
10
|
it("should extract the extension") { subject.extension.should == "1234" }
|
11
|
-
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "with a full NANP number with extension and appropriate daylight/standard time" do
|
15
|
+
subject { Dialable::NANP.parse("+1(307)555-1212 ext 1234") }
|
16
|
+
it("should determine the time zone during daylight savings or standard time") {
|
17
|
+
target_zone = Time.new.dst? ? "MDT" : "MST"
|
18
|
+
subject.timezones.should == [target_zone]
|
19
|
+
}
|
12
20
|
end
|
13
21
|
|
14
22
|
NANP = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data') + "/nanpa.yaml")
|
data/spec/spec.opts
ADDED
metadata
CHANGED
@@ -1,64 +1,136 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dialable
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- chorn
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tzinfo
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: tzinfo
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: A gem that provides parsing and output of phone numbers according to
|
79
|
+
NANPA (North American Numbering Plan Administration) standards. If possible, time
|
80
|
+
zones are populated by abbreviation as well as offset relative to the local timezone.
|
81
|
+
email:
|
82
|
+
- chorn@chorn.com
|
18
83
|
executables: []
|
19
|
-
|
20
84
|
extensions: []
|
21
|
-
|
22
85
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .travis.yml
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
25
91
|
- LICENSE
|
26
92
|
- README.rdoc
|
27
93
|
- Rakefile
|
28
94
|
- TODO
|
95
|
+
- data/dialable/nanpa.yaml
|
96
|
+
- data/nanpa.yaml
|
29
97
|
- dialable.gemspec
|
30
98
|
- lib/dialable.rb
|
31
|
-
-
|
99
|
+
- lib/dialable/version.rb
|
32
100
|
- spec/dialable_spec.rb
|
101
|
+
- spec/spec.opts
|
33
102
|
- spec/spec_helper.rb
|
34
103
|
- support/make_yaml_nanpa.rb
|
35
104
|
homepage: http://github.com/chorn/dialable
|
36
|
-
licenses:
|
105
|
+
licenses:
|
37
106
|
- MIT
|
38
107
|
- LGPL-2
|
39
108
|
post_install_message:
|
40
109
|
rdoc_options: []
|
41
|
-
|
42
|
-
require_paths:
|
110
|
+
require_paths:
|
43
111
|
- lib
|
44
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
113
|
none: false
|
46
|
-
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.9.0
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
119
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version:
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: -961668800609299415
|
56
127
|
requirements: []
|
57
|
-
|
58
128
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.8.
|
129
|
+
rubygems_version: 1.8.24
|
60
130
|
signing_key:
|
61
131
|
specification_version: 3
|
62
132
|
summary: Provides parsing and output of phone numbers according to NANPA standards.
|
63
|
-
test_files:
|
64
|
-
|
133
|
+
test_files:
|
134
|
+
- spec/dialable_spec.rb
|
135
|
+
- spec/spec.opts
|
136
|
+
- spec/spec_helper.rb
|