Class: ReportsListParser

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

Instance Method Summary collapse

Instance Method Details

#can_parse?(input) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/pr2gpx/parser.rb', line 68

def can_parse? input
  /Automated Reply Message from Winlink 2000 Position Report Processor/ =~ input
end

#parse(input) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/pr2gpx/parser.rb', line 72

def parse input
  Enumerator.new do |e|
    input.scan %r{
      \n\n(?<callsign>\w*)[ ]
      (?<year>\d+)/(?<month>\d+)/(?<day>\d+)[ ](?<hour>\d+):(?<minute>\d+)[ ]
      (?<latitude>[^\n]*)[ ]
      (?<longitude>[^\n]*)\n
      Comment:[ ](?<comment>[^\n]*)
    }xm do |callsign, year, month, day, hour, minute, latitude, longitude, comment|
      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