Class: Phony::NationalSplitters::Fixed

Inherits:
DSL
  • Object
show all
Defined in:
lib/phony/national_splitters/fixed.rb

Overview

TODO

Direct Known Subclasses

Regex, Variable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DSL

#>>, #country_for, #reserved

Constructor Details

#initialize(size, _options = {}) ⇒ Fixed

Returns a new instance of Fixed.



20
21
22
23
# File 'lib/phony/national_splitters/fixed.rb', line 20

def initialize(size, _options = {})
  @size = size
  @zero = nil # options[:zero] == false ? nil : '0'
end

Instance Attribute Details

#special_splitter=(value) ⇒ Object (writeonly)

Sets the attribute special_splitter

Parameters:

  • value

    the value to set the attribute special_splitter to.



8
9
10
# File 'lib/phony/national_splitters/fixed.rb', line 8

def special_splitter=(value)
  @special_splitter = value
end

Class Method Details

.instance_for(*parameters) ⇒ Object

Get a splitter for the given format.

Caches the created splitter for the given format.



16
17
18
# File 'lib/phony/national_splitters/fixed.rb', line 16

def self.instance_for *parameters
  @mapping[parameters] ||= new(*parameters)
end

Instance Method Details

#lengthObject

A valid length.



35
36
37
# File 'lib/phony/national_splitters/fixed.rb', line 35

def length
  @size
end

#split(national_number) ⇒ Object

Takes a national number and splits it into ndc and rest.



27
28
29
30
31
# File 'lib/phony/national_splitters/fixed.rb', line 27

def split(national_number)
  return [@zero, national_number] unless @size

  [@zero, national_number.slice!(0...@size), national_number]
end