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.
24 25 26 27 28 |
# File 'lib/phony/national_splitters/regex.rb', line 24 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.
14 15 16 |
# File 'lib/phony/national_splitters/regex.rb', line 14 def on_fail_take @on_fail_take end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
14 15 16 |
# File 'lib/phony/national_splitters/regex.rb', line 14 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.
20 21 22 |
# File 'lib/phony/national_splitters/regex.rb', line 20 def self.instance_for regex, on_fail_take = nil, = {} new regex, on_fail_take, end |
Instance Method Details
#length ⇒ Object
A valid length.
47 48 49 |
# File 'lib/phony/national_splitters/regex.rb', line 47 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)
35 36 37 38 39 40 41 42 43 |
# File 'lib/phony/national_splitters/regex.rb', line 35 def split national_number # Improve matching. # return [@zero, national_number.slice!(0..$1.size-1), national_number] if national_number =~ regex # Not found. # super national_number end |