class Phony::NationalSplitters::Regex

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.

Attributes

on_fail_take[R]
regex[R]

Public Class Methods

instance_for(regex, on_fail_take = nil, options = {}) click to toggle source

Get a splitter for the given format.

Note: Not cached.

# File lib/phony/national_splitters/regex.rb, line 20
def self.instance_for regex, on_fail_take = nil, options = {}
  new regex, on_fail_take, options
end
new(regex, on_fail_take = nil, options = {}) click to toggle source
Calls superclass method Phony::NationalSplitters::Fixed::new
# File lib/phony/national_splitters/regex.rb, line 24
def initialize regex, on_fail_take = nil, options = {}
  super on_fail_take, options

  @regex = regex
end

Public Instance Methods

length() click to toggle source

A valid length.

# 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) click to toggle source

Split a local number according to an assumed country specific format.

Examples

  • split ‘3643533’ # => [‘364’, ‘35’, ‘33’] # (Switzerland)

Calls superclass method Phony::NationalSplitters::Fixed#split
# 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