Class: Phony::NationalSplitters::Regex
- Defined in:
- lib/phony/national_splitters/regex.rb
Overview
National splitter class to split the ndc-local part of a number.
Countries can create new instances according to their needs.
Note: Countries should use instance_for
to avoid getting new local splitter instances.
Instance Attribute Summary collapse
-
#on_fail_take ⇒ Object
readonly
Returns the value of attribute on_fail_take.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Attributes inherited from Fixed
Class Method Summary collapse
-
.instance_for(regex, on_fail_take = nil, options = {}) ⇒ Object
Get a splitter for the given format.
Instance Method Summary collapse
-
#initialize(regex, on_fail_take = nil, options = {}) ⇒ Regex
constructor
A new instance of Regex.
-
#length ⇒ Object
A valid length.
-
#split(national_number) ⇒ Object
Split a local number according to an assumed country specific format.
Methods inherited from DSL
Constructor Details
#initialize(regex, on_fail_take = nil, options = {}) ⇒ Regex
Returns a new instance of Regex.
23 24 25 26 27 |
# File 'lib/phony/national_splitters/regex.rb', line 23 def initialize(regex, on_fail_take = nil, = {}) super(on_fail_take, ) @regex = regex end |
Instance Attribute Details
#on_fail_take ⇒ Object (readonly)
Returns the value of attribute on_fail_take.
13 14 15 |
# File 'lib/phony/national_splitters/regex.rb', line 13 def on_fail_take @on_fail_take end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
13 14 15 |
# File 'lib/phony/national_splitters/regex.rb', line 13 def regex @regex end |
Class Method Details
.instance_for(regex, on_fail_take = nil, options = {}) ⇒ Object
Get a splitter for the given format.
Note: Not cached.
19 20 21 |
# File 'lib/phony/national_splitters/regex.rb', line 19 def self.instance_for(regex, on_fail_take = nil, = {}) new regex, on_fail_take, end |
Instance Method Details
#length ⇒ Object
A valid length.
46 47 48 |
# File 'lib/phony/national_splitters/regex.rb', line 46 def length # raise "#{self.class.name} has no length that can be automatically extracted." end |
#split(national_number) ⇒ Object
Split a local number according to an assumed country specific format.
Examples
-
split ‘3643533’ # => [‘364’, ‘35’, ‘33’] # (Switzerland)
34 35 36 37 38 39 40 41 42 |
# File 'lib/phony/national_splitters/regex.rb', line 34 def split(national_number) # Improve matching. # return [@zero, national_number.slice!(0..::Regexp.last_match(1).size - 1), national_number] if national_number =~ regex # Not found. # super(national_number) end |