Sha256: 75bdd622e106fd2c6aa9fa912d20159d8a47100249064df3dc4e5a85ac70c672

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

require 'delegate'

module Barometer
  module WeatherService
    class ForecastIo
      class Query < SimpleDelegator
        attr_reader :converted_query

        def self.accepted_formats
          [:coordinates]
        end

        def initialize(query)
          super
          @converted_query = convert_query
        end

        def to_param
          @converted_query.q
        end

        def units_param
          {units: unit_type}
        end

        private

        def convert_query
          convert!(*self.class.accepted_formats)
        end

        def unit_type
          converted_query.metric? ? 'si' : 'us'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
barometer-0.9.2 lib/barometer/weather_services/forecast_io/query.rb
barometer-0.9.1 lib/barometer/weather_services/forecast_io/query.rb
barometer-0.9.0 lib/barometer/weather_services/forecast_io/query.rb