Class: BinaryBlocker::PackedDateTimeMMDDYYYYHHMMEncoder
Overview
Seems awfully specific, why is this here? Well my boss was nice enough to open source the code, so I figured something that made our (company) work easier could go in, even if I would have normally rejected it.
Instance Method Summary
collapse
#initialize
#inspect, register
Methods inherited from Encoder
#block, #deblock, #initialize, #key_value?, #me
Instance Method Details
#initialize_options(*opts) ⇒ Object
753
754
755
756
|
# File 'lib/blocker.rb', line 753
def initialize_options(*opts)
super
@opts[:length] = 12
end
|
#internal_block(val) ⇒ Object
758
759
760
761
762
763
764
|
# File 'lib/blocker.rb', line 758
def internal_block(val)
if val
super sprintf("%02d%02d%04d%02d%02d", val.month, val.mday, val.year, val.hour, val.min).to_i
else
super 0
end
end
|
#internal_deblock(io) ⇒ Object
766
767
768
769
770
771
772
773
774
775
|
# File 'lib/blocker.rb', line 766
def internal_deblock(io)
buffer = io.read(@bytes)
result = buffer.unpack(@format)
month, day, year, hour, min = result.first.unpack("A2A2A4A2A2").map { |v| v.to_i }
if month.zero?
nil
else
Time.local(year, month, day, hour, min, 0)
end
end
|
#valid? ⇒ Boolean
777
778
779
780
781
782
783
784
|
# File 'lib/blocker.rb', line 777
def valid?
case @value
when Time ; true
when nil ; true
else
false
end
end
|