Class: RSSParser

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

Instance Method Summary collapse

Instance Method Details

#can_parse?(input) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/pr2gpx/parser.rb', line 114

def can_parse? input
  /<rss version="2\.0">/ =~ input
end

#parse(input) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pr2gpx/parser.rb', line 118

def parse input
  Enumerator.new do |e|
    xml = Nokogiri::XML(input)
    xml.xpath('//item').each do |item|
      %r{^
        Position[ ]report[ ]for[ ]
        (?<callsign>[^ ]*)
        [ ]is[ ]
        (?<latitude>[^ ]*)
        [ ]/[ ]
        (?<longitude>[^ ]*)
      }x =~ item.xpath('title').first.content
      comment = item.xpath('description').first.content
      date = DateTime.parse(item.xpath('pubDate').first.content)
      e.yield PositionReport.new callsign,
                                 date,
                                 Position.new(latitude, longitude),
                                 comment
    end
  end
end