Method: NMEAPlus::SourceDecoder#each_message

Defined in:
lib/nmea_plus.rb

#each_message {|NMEAPlus::Message| ... } ⇒ void

This method returns an undefined value.

Executes the block for every valid NMEA message in the source stream. In practice, you should use #each_complete_message unless you have a very compelling reason not to.

Examples:

input = "$GPGGA,123519,4807.038,N,01131.000,W,1,08,0.9,545.4,M,46.9,M,2.2,123*4b"
io_source = StringIO.new(input)  # source decoder works on any IO object
source_decoder = NMEAPlus::SourceDecoder.new(io_source)
source_decoder.each_message do |message|
  if "GGA" == message.interpreted_data_type
    puts "Latitude: #{message.latitude} / Longitude: #{message.longtitude}"
    # prints "Latitude: 48.1173 / Longitude: -11.516666666666666666"
  end
end

Yields:


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nmea_plus.rb', line 45

def each_message
  @source.each_line do |line|
    if @throw_on_parse_fail
      yield @decoder.parse(line)
    else
      got_error = false
      begin
        y = @decoder.parse(line)
      rescue
        got_error = true
      end
      yield y unless got_error
    end
  end
end