Sha256: 73a03171550d0c36365e188fd14ed17260f8236eacd5867d586df94e348fce7d

Contents?: true

Size: 823 Bytes

Versions: 7

Compression:

Stored size: 823 Bytes

Contents

require 'delegate'

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

        def self.accepted_formats
          [:zipcode, :weather_id, :woe_id]
        end

        def initialize(query)
          super
          @converted_query = convert_query
        end

        def to_param
          {u: unit_type}.merge(format_query)
        end

        private

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

        def format_query
          if converted_query.format == :woe_id
            { w: converted_query.q }
          else
            { p: converted_query.q }
          end
        end

        def unit_type
          converted_query.metric? ? 'c' : 'f'
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
barometer-0.9.6 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.5 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.4 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.3 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.2 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.1 lib/barometer/weather_services/yahoo/query.rb
barometer-0.9.0 lib/barometer/weather_services/yahoo/query.rb