jbm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/jbm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jbm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,35 @@
1
+ module PhoneNumber
2
+ extend self
3
+ def extract(phone)
4
+ unless phone.blank?
5
+ phone.gsub!(/[^0-9]/, "")
6
+ phone.match(/(0+)/)
7
+ if !$1.blank? and phone.index($1).eql?(0)
8
+ phone.slice(($1.length)..-1)
9
+ else
10
+ phone
11
+ end
12
+ end
13
+ end
14
+
15
+ def parse(phone_number)
16
+ phone_number = extract(phone_number.to_s).to_s
17
+ regex = Regexp.new "\\A("+COUNTRIES.values.map{|c|c["country_code"] unless c["country_code"].blank?}.compact.uniq.join('|')+")"
18
+ phone_number.match(regex)
19
+ if !$1.blank? and phone_number.index($1).eql?(0)
20
+ {:country_code=> phone_number.slice(0..($1.length-1)),
21
+ :number=>phone_number.slice(($1.length)..-1)}
22
+ end
23
+ end
24
+
25
+ def prefix_country_code(phone_number, alpha2 = 'US')
26
+ unless phone_number.blank?
27
+ country = COUNTRIES[alpha2 || 'US']
28
+ unless country.blank?
29
+ phone_number.is_a?(Array) ? phone_number.map{|phno|country["country_code"]+phno.to_s} : country["country_code"]+phone_number.to_s
30
+ else
31
+ phone_number
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,19 +46,26 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
+ - .idea/.name
50
+ - .idea/.rakeTasks
49
51
  - .idea/encodings.xml
50
52
  - .idea/jbm.iml
51
53
  - .idea/misc.xml
52
54
  - .idea/modules.xml
53
55
  - .idea/scopes/scope_settings.xml
54
56
  - .idea/vcs.xml
57
+ - .idea/workspace.xml
55
58
  - Gemfile
56
59
  - LICENSE.txt
57
60
  - README.md
58
61
  - Rakefile
62
+ - jbm-0.0.1.gem
59
63
  - jbm.gemspec
60
- - lib/jbm.rb
64
+ - lib/config.rb
65
+ - lib/country.rb
66
+ - lib/data/countries.yml
61
67
  - lib/jbm/version.rb
68
+ - lib/phone_number.rb
62
69
  homepage: ''
63
70
  licenses:
64
71
  - MIT
data/lib/jbm.rb DELETED
@@ -1,7 +0,0 @@
1
- require "jbm/version"
2
-
3
- module Jbm
4
- def self.ipsum
5
- "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
6
- end
7
- end