Class: BinaryBlocker::PackedDateEncoderMMDDYYYY
Instance Method Summary
collapse
#initialize
#inspect, register
Methods inherited from Encoder
#block, #deblock, #initialize, #key_value?, #me
Instance Method Details
#initialize_options(*opts) ⇒ Object
632
633
634
635
|
# File 'lib/blocker.rb', line 632
def initialize_options(*opts)
super
@opts[:length] = 8
end
|
#internal_block(val) ⇒ Object
637
638
639
640
641
642
643
|
# File 'lib/blocker.rb', line 637
def internal_block(val)
if val
super val.month * 1000000 + val.mday * 10000 + val.year
else
super 0
end
end
|
#internal_deblock(io) ⇒ Object
645
646
647
648
649
650
651
652
653
654
|
# File 'lib/blocker.rb', line 645
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
656
657
658
659
660
661
662
663
664
|
# File 'lib/blocker.rb', line 656
def valid?
case @value
when Date ; true
when Time ; true
when nil ; true
else
false
end
end
|