lib/dmapparser/parser.rb in dmapparser-0.1.0 vs lib/dmapparser/parser.rb in dmapparser-0.2.0

- old
+ new

@@ -16,12 +16,11 @@ @response = StringIO.new(response) unless @response.is_a? IO @response.set_encoding(Encoding::BINARY) end def parse - return nil if @response.nil? || @response.size == 0 - fail ParseError if @response.size < 8 + fail ParseError if @response.nil? || @response.size < 8 ret = TagContainer.new(read_key) fail ParseError if ret.type && !ret.type.container? ret.value = parse_container(read_length) ret end @@ -35,12 +34,10 @@ def bytes_available?(num = 1) bytes_left - num >= 0 end def read_bytes(length) - unless bytes_available?(length) - fail ParseError, 'Not enough data available' - end + fail ParseError, 'Not enough data available' unless bytes_available?(length) @response.read(length) end def read_length Converter.bin_to_int(read_bytes(4))