Sha256: 792c24abf2c1b797274b2e75265acb2618dc1217547a3c0c653b88e5e78648c8

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

require_relative 'apis/noaa_station'
require 'nokogiri'

module Barometer
  module Query
    module Service
      class NoaaStation
        def self.fetch(query)
          converted_query = query.get_conversion(:coordinates)
          return unless converted_query

          api = NoaaStation::Api.new(converted_query)
          _parse_content(api.get)
        end

        def self._parse_content(content)
          doc = Nokogiri::HTML.parse(content)

          if doc
            extra_links = doc.search(".current-conditions-extra a")

            if sid_link = extra_links.detect{|link| link.attr('href').match(/sid=(.*)&/)}
              sid_link.attr('href').match(/sid=(.*?)&/)[1]
            elsif three_day_link = extra_links.detect{|link| link.text.match(/3 Day History/)}
              three_day_link.attr('href').match(/\/([A-Za-z]*?)\.html/)[1]
            end
          end
        rescue
          nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
barometer-0.9.7 lib/barometer/query/services/noaa_station_id.rb