phony 2.9.1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 117a11d3df055c88a892d0cbb32a1106e72d2ed6
4
- data.tar.gz: 6b9d3d5ab8e6e2c1559a0b670865fb9727006492
3
+ metadata.gz: 149c31aeeafd871ed8e08201ade25314998da9e1
4
+ data.tar.gz: f9160fe2f2da602bbb10259d95f4a12bea57290b
5
5
  SHA512:
6
- metadata.gz: 4cc3f3eed1456898a67e536a3a996b3a32ea81b10fcbec18082a80d0dcf096a41bf731ffb4822bc66a03f48d16df350aee5a2b1696b3a0a1b690c1a3d42bdb3a
7
- data.tar.gz: 1fa24b6a8326fe7989b3f8f25be1af5a101238515c87fa2d39b3f08f50593263f17ba470d8ae97aa712b26c52b48304b4fe68860d6f5ef8516ef60fcb650f603
6
+ metadata.gz: 62f5e978d9aa5331c924f14c86efc9251d057f6c140ef606ff8d33c05a10d30735a2aa2e2745ad1f68f4d6ed398405bf3933614af3d356c2b80527bf140b4d89
7
+ data.tar.gz: 3fec76eb6b6359e3ee54e9f6c373f062a1e25850650e1d7291db71d69005787269893e8463770973bf04e8b7125e8fa20e509ce18e773a28fc45b193ab9b6f09
@@ -124,5 +124,6 @@ Phony.define do
124
124
  one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
125
125
  one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
126
126
  one_of(%w(995344 9971 99744 9976 997)) >> split(2, 4) | # South Osetia
127
- fixed(3) >> split(2, 5)
127
+ fixed(3) >> split(2, 5),
128
+ :local_space => :-
128
129
  end
@@ -3,7 +3,8 @@ module Phony
3
3
  #
4
4
  #
5
5
  class Country
6
-
6
+
7
+ attr_reader :format, :space, :local_space
7
8
  attr_accessor :codes
8
9
 
9
10
  #
@@ -26,6 +27,9 @@ module Phony
26
27
  def with cc, options = {}
27
28
  @cc = cc
28
29
  @invalid_ndcs = options[:invalid_ndcs] || []
30
+ @format = options[:format]
31
+ @space = options[:space]
32
+ @local_space = options[:local_space]
29
33
  end
30
34
 
31
35
  # A number is split with the code handlers as given in the initializer.
@@ -80,15 +80,22 @@ module Phony
80
80
  # Splits this number into cc, ndc and locally split number parts.
81
81
  #
82
82
  def split number
83
+ country, *cc_split_rest = internal_split number
84
+ cc_split_rest
85
+ end
86
+
87
+ def internal_split number
83
88
  country, cc, rest = split_cc number
84
- [cc, *country.split(rest)]
89
+ [country, cc, *country.split(rest)]
85
90
  end
86
91
 
87
92
  def format number, options = {}
88
- format_cc_ndc_local options[:format],
89
- options[:spaces] || @default_space,
90
- options[:local_spaces] || options[:spaces] || @default_local_space,
91
- *split(number)
93
+ country, *split_number = internal_split number
94
+ format_cc_ndc_local \
95
+ options[:format] || country.format,
96
+ options[:spaces] || country.space || @default_space,
97
+ options[:local_spaces] || country.local_space || options[:spaces] || @default_local_space,
98
+ *split_number
92
99
  end
93
100
  alias formatted format
94
101
 
@@ -70,13 +70,13 @@ describe 'Phony#format' do
70
70
  Phony.format(Phony.normalize('+370 800 12345'), :format => :international).should eql '+370 800 12 345'
71
71
  end
72
72
  it 'should format Russian numbers' do
73
- Phony.format(Phony.normalize('+7 812 123 4567'), :format => :international).should eql '+7 812 123 45 67'
73
+ Phony.format(Phony.normalize('+7 812 123 4567'), :format => :international).should eql '+7 812 123-45-67'
74
74
  end
75
75
  it 'should format Russian numbers' do
76
76
  Phony.format(Phony.normalize('+370 800 12345'), :format => :national).should eql '8800 12 345'
77
77
  end
78
78
  it 'should format Russian numbers' do
79
- Phony.format(Phony.normalize('+7 812 123 4567'), :format => :national).should eql '8812 123 45 67'
79
+ Phony.format(Phony.normalize('+7 812 123 4567'), :format => :national).should eql '8812 123-45-67'
80
80
  end
81
81
  end
82
82
  describe 'international' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.1
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke