Class: BinaryBlocker::PackedDateEncoderMMDDYYYY

Inherits:
PackedNumberEncoder show all
Defined in:
lib/blocker.rb

Instance Method Summary collapse

Methods inherited from PackedNumberEncoder

#initialize

Methods inherited from SimpleEncoder

#inspect, register

Methods inherited from Encoder

#block, #deblock, #initialize, #key_value?, #me

Constructor Details

This class inherits a constructor from BinaryBlocker::PackedNumberEncoder

Instance Method Details

#initialize_options(*opts) ⇒ Object



629
630
631
632
# File 'lib/blocker.rb', line 629

def initialize_options(*opts)
  super
  @opts[:length] = 8
end

#internal_block(val) ⇒ Object



634
635
636
637
638
639
640
# File 'lib/blocker.rb', line 634

def internal_block(val)
  if val
    super val.month * 1000000 + val.mday * 10000 + val.year
  else
    super 0
  end 
end

#internal_deblock(io) ⇒ Object



642
643
644
645
646
647
648
649
650
651
# File 'lib/blocker.rb', line 642

def internal_deblock(io)
  buffer = io.read(@bytes)
  result = buffer.unpack(@format)
  month, day, year = result.first.unpack("A2A2A4").map { |v| v.to_i }
  if month.zero?
    nil
  else
    Date.civil(year, month, day)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


653
654
655
656
657
658
659
660
661
# File 'lib/blocker.rb', line 653

def valid?
  case @value
  when Date ; true
  when Time ; true
  when nil  ; true
  else 
    false
  end        
end