Module: Zip5
- Defined in:
- lib/zip5.rb,
lib/zip5/version.rb
Constant Summary collapse
- VALID =
501..99950
- VERSION =
'0.0.2'
Class Method Summary collapse
Class Method Details
.zip4(input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zip5.rb', line 30 def Zip5.zip4(input) input = input.to_s.gsub(/\.\d*\z/, '') memo = nil if input =~ /\A\d+\-(\d+)\z/ memo = $1.to_i elsif zip5 = zip5(input) hunk = zip5.gsub /\A0*/, '' pat = /\A0*#{hunk}/ memo = input.gsub(pat, '').to_i end if memo and memo > 0 '%04d' % memo.to_i end end |
.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.gsub('-', '') 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 |