Class: NearbyStationsParser

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

Instance Method Summary collapse

Instance Method Details

#can_parse?(input) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/pr2gpx/parser.rb', line 91

def can_parse? input
  /List of users nearby/ =~ input
end

#parse(input) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/pr2gpx/parser.rb', line 95

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