Sha256: e7afe109af4400fc73a5511b110afcbdb2cb29d0520bbab319cddb0027f2b04e

Contents?: true

Size: 892 Bytes

Versions: 3

Compression:

Stored size: 892 Bytes

Contents

require 'delegate'

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

        def self.accepted_formats
          [:short_zipcode, :coordinates]
        end

        def initialize(query)
          super
          @converted_query = convert_query
        end

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

        private

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

        def format_query
          if converted_query.format == :short_zipcode
            {zipCode: converted_query.q}
          else
            {lat: converted_query.geo.latitude, long: converted_query.geo.longitude}
          end
        end

        def unit_type
          converted_query.metric? ? '1' : '0'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
barometer-0.9.4 lib/barometer/weather_services/weather_bug/query.rb
barometer-0.9.3 lib/barometer/weather_services/weather_bug/query.rb
barometer-0.9.2 lib/barometer/weather_services/weather_bug/query.rb