Class: Phony::NationalSplitters::Fixed
- Defined in:
- lib/phony/national_splitters/fixed.rb
Overview
TODO
Instance Attribute Summary collapse
-
#special_splitter ⇒ Object
writeonly
Sets the attribute special_splitter.
Class Method Summary collapse
-
.instance_for(*parameters) ⇒ Object
Get a splitter for the given format.
Instance Method Summary collapse
-
#initialize(size, _options = {}) ⇒ Fixed
constructor
A new instance of Fixed.
-
#length ⇒ Object
A valid length.
-
#split(national_number) ⇒ Object
Takes a national number and splits it into ndc and rest.
Methods inherited from DSL
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, = {}) @size = size @zero = nil # options[:zero] == false ? nil : '0' end |
Instance Attribute Details
#special_splitter=(value) ⇒ Object (writeonly)
Sets the attribute special_splitter
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
#length ⇒ Object
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 |