Sha256: eca1df6ae9dd3ef3e5af5dc95152f81159d3cf097640578cce3f32fc105a01c4

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

module Barometer

  class Base
    
    # allow the configuration of specific weather APIs to be used,
    # and the order in which they would be used
    @@selection = { 1 => [:wunderground] }
    def self.selection; @@selection; end;
    def self.selection=(hash); @@selection = hash; end;
    
    attr_reader   :query
    attr_accessor :weather, :success
    
    def initialize(query=nil)
      @query = Barometer::Query.new(query)
      @weather = Barometer::Weather.new
      @success = false
    end
    
    def measure(metric=nil)
      return nil unless @query

      level = 1
      until self.success?
        if sources = @@selection[level]
          if sources.is_a?(Array)
            sources.each do |source|
              measurement = Barometer.source(source.to_sym).measure(@query, metric)
              @success = true if measurement.success?
              @weather.measurements << measurement
            end
          else  
            measurement = Barometer.source(sources.to_sym).measure(@query, metric)
            @success = true if measurement.success?
            @weather.measurements << measurement
          end
        else
          raise OutOfSources
        end
        level += 1
      end
      
      @weather
    end
    
    def success?
      @success
    end

  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
attack-barometer-0.1.0 lib/barometer/base.rb
attack-barometer-0.2.3 lib/barometer/base.rb
attack-barometer-0.3.1 lib/barometer/base.rb
attack-barometer-0.3.2 lib/barometer/base.rb
barometer-0.1.0 lib/barometer/base.rb
barometer-0.3.2 lib/barometer/base.rb
barometer-0.3.1 lib/barometer/base.rb
barometer-0.2.3 lib/barometer/base.rb
barometer-0.2.2 lib/barometer/base.rb
barometer-0.2.1 lib/barometer/base.rb