ruphone 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7b6aadfab7520af5590a73dd559f0854f6af089
4
+ data.tar.gz: c445f93093c79b0ffb1192c0065bb2cae0e777bc
5
+ SHA512:
6
+ metadata.gz: 8340b50f44a895f31b78d18b514283791cd93f5a94283babd556fb8313062e260943b64e897560f28939f715536eeb4c35bd29df17273d10424291a474c51aba
7
+ data.tar.gz: 4a64d68ce22cb4aec5e388e656cbad439953b022fa82ddb0d4f066126a3639d4c1e47b5600b47f43e55a436e7445e000c182ad163687e8f443db3701fa4820e0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Artem Baikuzin
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,30 @@
1
+ # Ruphone
2
+
3
+ Normalize russian phone numbers to +7XXXXXXXXXX format. Examples:
4
+
5
+ ```ruby
6
+ Ruphone.normalize('8921-746-95-48')
7
+ # => "+79217469548"
8
+
9
+ Ruphone.normalize('8(921) 746-95-48')
10
+ # => "+79217469548"
11
+
12
+ Ruphone.normalize('746-95-48', city_code: '+7843')
13
+ # => "+78437469548"
14
+ ```
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'ruphone'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install ruphone
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 => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruphone"
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(__FILE__)
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,3 @@
1
+ module Ruphone
2
+ VERSION = '0.0.1'
3
+ end
data/lib/ruphone.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'ruphone/version'
2
+
3
+ module Ruphone
4
+ # Normalize russian phone numbers to +7XXXXXXXXXX format. Examples:
5
+ #
6
+ # Ruphone.normalize('8921-746-95-48')
7
+ # # => "+79217469548"
8
+ #
9
+ # Ruphone.normalize('8(921) 746-95-48')
10
+ # # => "+79217469548"
11
+ #
12
+ # Ruphone.normalize('746-95-48', city_code: '+7843')
13
+ # # => "+78437469548"
14
+ #
15
+ def self.normalize(phone, args = {})
16
+ return phone if phone.nil?
17
+
18
+ phone = phone.tr('^0-9', '')
19
+ return phone if phone.size.zero?
20
+
21
+ return prefix(phone) if phone.size == 10
22
+
23
+ if phone.size == 11
24
+ return plus(phone) if phone.start_with?('7')
25
+ return prefix(phone[1..-1]) if phone.start_with?('8')
26
+ end
27
+
28
+ city_code = normalize_city_code(args[:city_code])
29
+ if city_code && phone.size == 11 - city_code.size
30
+ return plus("#{city_code}#{phone}")
31
+ end
32
+
33
+ phone
34
+ end
35
+
36
+ private
37
+
38
+ def self.prefix(phone)
39
+ "+7#{phone}"
40
+ end
41
+
42
+ def self.plus(phone)
43
+ "+#{phone}"
44
+ end
45
+
46
+ def self.normalize_city_code(city_code)
47
+ return city_code if city_code.nil?
48
+ return city_code[1..-1] if city_code.start_with?('+')
49
+ city_code
50
+ end
51
+ end
data/ruphone.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruphone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruphone'
8
+ spec.version = Ruphone::VERSION
9
+ spec.authors = ['Artem Baikuzin']
10
+ spec.email = ['ybinzu@gmail.com']
11
+
12
+ spec.summary = %q{Normalize russian phone numbers to +7XXXXXXXXXX}
13
+ spec.description = %q{Normalize russian phone numbers to +7XXXXXXXXXX}
14
+ spec.homepage = 'https://github.com/ybinzu/ruphone'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruphone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Artem Baikuzin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Normalize russian phone numbers to +7XXXXXXXXXX
42
+ email:
43
+ - ybinzu@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-version"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/ruphone.rb
57
+ - lib/ruphone/version.rb
58
+ - ruphone.gemspec
59
+ homepage: https://github.com/ybinzu/ruphone
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.13
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Normalize russian phone numbers to +7XXXXXXXXXX
83
+ test_files: []