alexander_graham_bell 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 384bd7567d4ca649ce2b65748300e1591edcb2d8
4
+ data.tar.gz: 61b36765489fcd9d3b8df756cca1ec568dc973ce
5
+ SHA512:
6
+ metadata.gz: 6e267e6e5c32d66ba98a269c835ca6d9fcebebccf65c32f62df0f15ce3c48b1ba4f36a79912e0f961747ef0383c00b95faae504e1902567123827f488fa26fe3
7
+ data.tar.gz: 8e9e991b5e3e6093cfbb32c74b5f6cde70ccb15f4535dc0138509419768a84461ef4d4f3c4ec3f19fbc8908634c6948b860c7df918234480f5a0b96f332da2f5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alexander_graham_bell.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Scott Speidel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # alexander-graham-bell
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alexander_graham_bell/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alexander_graham_bell"
8
+ spec.version = AlexanderGrahamBell::VERSION
9
+ spec.authors = ["Scott Speidel","Michael Jewell"]
10
+ spec.email = ["scottspeidel@gmail.com", "michaeljewell9911@gmail.com"]
11
+
12
+ spec.summary = %q{Phone number parser and tel link creator.}
13
+ spec.homepage = "https://github.com/appfolio/alexander-graham-bell"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alexander_graham_bell"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ module AlexanderGrahamBell
2
+ class Phone
3
+ # modified from https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s02.html#I_programlisting4_d1e22044
4
+ # ORIGINAL_REGEX = /^(\+?1)?[-.\s]*\(?([2-9][0-8]\d)\)?[-.\s]*([2-9]\d{2})[-.\s]*(\d{4})\s*((x|ext)\s*\d+)?$/i
5
+ INTERNATIONAL_REGEX = /^(\+?1)?/
6
+ AREA_CODE_REGEX = /([2-9][0-8]\d)?/
7
+ TELEPHONE_EXCHANGE_REGEX = /([2-9]\d{2})/
8
+ LINE_NUMBER_REGEX = /(\d{4})/
9
+ EXTENSION_REGEX = /(?:(?:,|,?(?:x|ext|extension):?)(\d+))?$/i
10
+ PHONE_REGEX = /(?:(?:#{INTERNATIONAL_REGEX}#{AREA_CODE_REGEX})?#{TELEPHONE_EXCHANGE_REGEX}#{LINE_NUMBER_REGEX}#{EXTENSION_REGEX})?/
11
+
12
+ attr_reader :international, :area_code, :telephone_exchange, :line_number, :extension
13
+
14
+ def initialize(phone_number)
15
+ unless phone_number.instance_of?(String)
16
+ raise TypeError,
17
+ "Expected phone_number to be of type String but got #{phone_number.class.name}"
18
+ end
19
+
20
+ phone_number = clean(phone_number)
21
+
22
+ @international, @area_code, @telephone_exchange, @line_number, @extension = PHONE_REGEX.match(phone_number).captures
23
+ end
24
+
25
+ def valid?
26
+ return [@telephone_exchange, @line_number].all?
27
+ end
28
+
29
+ def number
30
+ [@international, @area_code, @telephone_exchange, @line_number].reject(&:nil?).join
31
+ end
32
+
33
+ def number_with_extension(extension_separator = ' ext ')
34
+ extension = @extension.nil? ? '' : extension_separator + @extension
35
+ number + extension
36
+ end
37
+
38
+ private
39
+
40
+ def clean(dirty_number)
41
+ dirty_number.gsub(/[-.()\s]/, '')
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module AlexanderGrahamBell
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'erb'
2
+ require 'alexander_graham_bell/version'
3
+ require 'alexander_graham_bell/phone'
4
+
5
+ module AlexanderGrahamBell
6
+ def self.tel_link(phone_number, escaper = ERB::Util.method(:h))
7
+ phone = Phone.new(phone_number)
8
+ escaped_phone_number = escaper ? escaper.call(phone_number) : phone_number
9
+ return escaped_phone_number unless phone.valid?
10
+ "<a href=\"tel:#{phone.number}#{isub(phone)}\">#{escaped_phone_number}</a>"
11
+ end
12
+
13
+ private
14
+
15
+ def self.isub(phone)
16
+ ";isub=#{phone.extension}" unless phone.extension.nil?
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexander_graham_bell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Speidel
8
+ - Michael Jewell
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ description:
57
+ email:
58
+ - scottspeidel@gmail.com
59
+ - michaeljewell9911@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - alexander_graham_bell.gemspec
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/alexander_graham_bell.rb
74
+ - lib/alexander_graham_bell/phone.rb
75
+ - lib/alexander_graham_bell/version.rb
76
+ homepage: https://github.com/appfolio/alexander-graham-bell
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Phone number parser and tel link creator.
100
+ test_files: []