binaryparse 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/blocker.rb +41 -2
- metadata +1 -1
data/lib/blocker.rb
CHANGED
@@ -674,7 +674,46 @@ module BinaryBlocker
|
|
674
674
|
BinaryBlocker.register_klass(:time_hhmm, PackedDateTimeHHMMEncoder)
|
675
675
|
BinaryBlocker.register_klass(:date_hhmm, PackedDateTimeHHMMEncoder)
|
676
676
|
|
677
|
-
|
677
|
+
# Seems awfully specific, why is this here? Well my boss was nice
|
678
|
+
# enough to open source the code, so I figured something that made
|
679
|
+
# our (company) work easier could go in, even if I would have
|
680
|
+
# normally rejected it.
|
681
|
+
class PackedDateTimeMMDDYYYYHHMMEncoder < PackedNumberEncoder
|
682
|
+
def initialize_options(*opts)
|
683
|
+
super
|
684
|
+
@opts[:length] = 12
|
685
|
+
end
|
686
|
+
|
687
|
+
def internal_block(val)
|
688
|
+
if val
|
689
|
+
super sprintf("%02d%02d%04d%02d%02d", val.month, val.mday, val.year, val.hour, val.min).to_i
|
690
|
+
else
|
691
|
+
super 0
|
692
|
+
end
|
693
|
+
end
|
694
|
+
|
695
|
+
def internal_deblock(io)
|
696
|
+
buffer = io.read(@bytes)
|
697
|
+
result = buffer.unpack(@format)
|
698
|
+
month, day, year, hour, min = result.first.unpack("A2A2A4A2A2").map { |v| v.to_i }
|
699
|
+
if month.zero?
|
700
|
+
nil
|
701
|
+
else
|
702
|
+
Time.local(year, month, day, hour, min, 0)
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
def valid?
|
707
|
+
case @value
|
708
|
+
when Time : true
|
709
|
+
when nil : true
|
710
|
+
else
|
711
|
+
false
|
712
|
+
end
|
713
|
+
end
|
714
|
+
end
|
715
|
+
BinaryBlocker.register_klass(:date_mmddyyyyhhmm, PackedDateTimeMMDDYYYYHHMMEncoder)
|
716
|
+
|
678
717
|
class OneOfEncoder < Encoder
|
679
718
|
|
680
719
|
def inspect
|
@@ -925,4 +964,4 @@ module BinaryBlocker
|
|
925
964
|
end
|
926
965
|
end
|
927
966
|
|
928
|
-
end
|
967
|
+
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: binaryparse
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
6
|
+
version: 0.2.6
|
7
7
|
date: 2006-12-08 00:00:00 -05:00
|
8
8
|
summary: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
9
9
|
require_paths:
|