Class: Depix::CharField
Constant Summary
collapse
- BLANK =
"\0"
- BLANKING_VALUES =
[0x00.chr, 0xFF.chr]
- BLANKING_PATTERNS =
BLANKING_VALUES.inject([]) do | p, char |
p << /^([#{char}]+)/ << /([#{char}]+)$/mu
end
Instance Attribute Summary
Attributes inherited from Field
#desc, #length, #name, #req
Instance Method Summary
collapse
Methods inherited from Field
#consume!, emit_char, emit_r32, emit_u16, emit_u32, emit_u8, #explain, #initialize
Constructor Details
This class inherits a constructor from Depix::Field
Instance Method Details
#clean(v) ⇒ Object
231
232
233
234
235
236
237
238
239
|
# File 'lib/depix/dict.rb', line 231
def clean(v)
if v == BLANK
nil
else
upto_nulb = v.split(0x00.chr).shift
(upto_nulb.nil? || upto_nulb.empty?) ? nil : upto_nulb
end
end
|
#pack(value) ⇒ Object
250
251
252
|
# File 'lib/depix/dict.rb', line 250
def pack(value)
value.ljust(length, "\000") rescue ("\000" * length)
end
|
#pattern ⇒ Object
227
228
229
|
# File 'lib/depix/dict.rb', line 227
def pattern
"A#{(length || 1).to_i}"
end
|
#rtype ⇒ Object
241
242
243
|
# File 'lib/depix/dict.rb', line 241
def rtype
String
end
|
#validate!(value) ⇒ Object
245
246
247
248
|
# File 'lib/depix/dict.rb', line 245
def validate!(value)
super(value)
raise "#{value} overflows the #{length} bytes allocated" if !value.nil? && value.length > length
end
|