Module: Protokoll::ExtractNumber

Defined in:
lib/protokoll/extract_number.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) create_number_mask(format)



3
4
5
6
7
# File 'lib/protokoll/extract_number.rb', line 3

def self.create_number_mask(format)
  format.split("").map do |i|
    (i == "#") ? 1 : 0
  end
end

+ (Object) expand_pattern(pattern)



21
22
23
# File 'lib/protokoll/extract_number.rb', line 21

def self.expand_pattern(pattern)
  pattern.sub("%Y", "0000")
end

+ (Object) extract_using_mask(db_number, mask)



9
10
11
12
13
14
# File 'lib/protokoll/extract_number.rb', line 9

def self.extract_using_mask(db_number, mask)
  result = db_number.split("").select.with_index do |n, i| 
    n if mask[i] == 1
  end
  result.join.to_i
end

+ (Object) number(str, pattern)



16
17
18
19
# File 'lib/protokoll/extract_number.rb', line 16

def self.number(str, pattern)
  mask = create_number_mask( expand_pattern(pattern) )
  extract_using_mask(str, mask)
end