Class: OutboundReportParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pr2gpx/parser.rb

Instance Method Summary collapse

Instance Method Details

#can_parse?(input) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pr2gpx/parser.rb', line 44

def can_parse? input
  /Subject: POSITION REPORT/ =~ input
end

#parse(input) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pr2gpx/parser.rb', line 48

def parse input
  Enumerator.new do |e|
    if %r{
      (X-From:[ ](?<callsign>[^\n]*))\n
      .*
      (TIME:[ ](?<year>\d+)/(?<month>\d+)/(?<day>\d+)[ ](?<hour>\d+):(?<minute>\d+))\n
      (LATITUDE:[ ](?<latitude>[^\n]*))\n
      (LONGITUDE:[ ](?<longitude>[^\n]*))\n
      (COMMENT:[ ](?<comment>[^\n]*))}xm =~ input
    then
      e.yield PositionReport.new callsign,
                                 DateTime.new(year.to_i, month.to_i, day.to_i, hour.to_i, minute.to_i, 0),
                                 Position.new(latitude, longitude),
                                 comment
    end
  end
end