class Phony::NationalSplitters::Variable
Public Class Methods
Source
# File lib/phony/national_splitters/variable.rb, line 6 def initialize(fallback, ndcs, options = {}) super(fallback, options) @ndcs = optimize ndcs end
Calls superclass method
Phony::NationalSplitters::Fixed::new
Public Instance Methods
Source
# File lib/phony/national_splitters/variable.rb, line 46 def length (@mapped_ndc_min_length..@mapped_ndc_max_length) end
A valid length.
Source
# File lib/phony/national_splitters/variable.rb, line 13 def split(national_number) national_number = national_number.dup fallback_number = national_number.dup # Extract a starting point. # # This if can possibly be removed. # presumed_code = if @mapped_ndc_min_length.positive? presumed_code = national_number.slice!(0..@mapped_ndc_min_length - 1) else '' end # Try for all possible mapped. # @mapped_ndc_min_length.upto @mapped_ndc_max_length do |i| ndcs_of_size_i = @ndcs[i] unless ndcs_of_size_i && !ndcs_of_size_i.include?(presumed_code) return [@zero, presumed_code, national_number] end presumed_code << national_number.slice!(0..0) end # Not found. # super(fallback_number) end
Takes a national number and splits it into ndc and rest.
Calls superclass method
Phony::NationalSplitters::Fixed#split
Private Instance Methods
Source
# File lib/phony/national_splitters/variable.rb, line 54 def optimize(ndc_ary) ndcs = {} ndc_ary.each do |ndc| ndcs[ndc.length] ||= [] ndcs[ndc.length] << ndc end keys = ndcs.keys @mapped_ndc_min_length = keys.min # || 1 @mapped_ndc_max_length = keys.max ndcs end
Optimizes and restructures the given ndcs array.