Module: Zip5

Defined in:
lib/zip5.rb,
lib/zip5/version.rb

Constant Summary collapse

VALID =
501..99950
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.zip5(input) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zip5.rb', line 6

def Zip5.zip5(input)
  input = input.to_i.to_s.delete('-')
  memo = case input.length
  when 9
    input[0,5]
  when 8
    '0' + input[0,4]
  when 7
    '00' + input[0,3]
  when 5
    input
  when 4
    '0' + input
  when 3
    '00' + input
  else
    nil
  end
  if ENV['VERBOSE'] == 'true' and not VALID.include?(memo.to_i)
    $stderr.puts "warning: looks like a bad zip5 (expected 00500..99950): #{memo}"
  end
  memo
end