Sha256: 004dc31ec32448dc1671232aebf335e71a6b259702d4b327592ad19860732dc5

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module GeoNamesAPI
  class Weather < List

    METHOD = "findNearByWeatherJSON"
    FIND_PARAMS = %w(lat lng radius)

    def geo_names_api_country
      @geo_names_api_country ||= GeoNamesAPI::Country.find(country_code)
    end

    def geo_names_api_time_zone
      @geo_names_api_time_zone ||= GeoNamesAPI::TimeZone.find(lat, lng)
    end

    def time_zone
      geo_names_api_time_zone.time_zone
    end

    def at_local
      t = DateTime.parse(datetime)
      time_zone.local(t.year, t.month, t.day, t.hour, t.minute)
    end

    def at_utc
      at_local.utc
    end

    def elevation_feet
      elevation * 3.28084 if elevation
    end

    def elevation_meters
      elevation if elevation
    end

    def convert_c_to_f(temp)
      temp * 9.to_f / 5.to_f + 32
    end

    def temperature_f
      convert_c_to_f(temperature) if temperature
    end

    def temperature_c
      temperature if temperature
    end

    def dew_point_f
      convert_c_to_f(dew_point) if temperature
    end

    def dew_point_c
      dew_point if temperature
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geonames_api-0.1.0 lib/geonames_api/weather.rb