Method: EchiConverter#dump_binary
- Defined in:
- lib/echi-converter.rb
#dump_binary(type, length) ⇒ Object
Method for parsing the various datatypes from the ECH file
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/echi-converter.rb', line 185 def dump_binary type, length @log.debug "dump_binary method" case type when 'int' #Process integers, assigning appropriate profile based on length #such as long int, short int and tiny int. case length when 4 value = @binary_file.read(length).unpack("l").first.to_i when 2 value = @binary_file.read(length).unpack("s").first.to_i when 1 value = @binary_file.read(length).unpack("U").first.to_i end #Process appropriate intergers into datetime format in the database when 'datetime' case length when 4 value = @binary_file.read(length).unpack("l").first.to_i value = Time.at(value) end #Process strings when 'str' value = @binary_file.read(length).unpack("M").first.to_s.rstrip #Process individual bits that are booleans when 'bool' value = @binary_file.read(length).unpack("b8").last.to_s #Process that one wierd boolean that is actually an int, instead of a bit when 'boolint' value = @binary_file.read(length).unpack("U").first.to_i #Change the values of the field to Y/N for the varchar(1) representation of BOOLEAN if value == 1 value = 'Y' else value = 'N' end end return value end |