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


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

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.


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

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.


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

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.


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

def split national_number
  return [@zero, national_number] unless @size
  [@zero, national_number.slice!(0...@size), national_number]
end