Class: WeatherFetcher::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_fetcher/fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFetcher

Returns a new instance of Fetcher.



10
11
12
# File 'lib/weather_fetcher/fetcher.rb', line 10

def initialize
  @logger = Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/weather_fetcher/fetcher.rb', line 8

def logger
  @logger
end

Instance Method Details

#fetch(defs, max_response_time = 0.8) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/weather_fetcher/fetcher.rb', line 14

def fetch(defs, max_response_time = 0.8)
  require 'yaml'
  classes = ProviderList.providers(max_response_time)
  result = Array.new

  classes.each do |c|
    self.logger.debug("#{self.class.to_s.blue} - starting #{c.to_s.red} with #{defs.size.to_s.green} definitions")

    instance = c.new(defs)
    instance.logger = self.logger
    instance.fetch
    class_results = instance.weathers

    self.logger.debug("#{self.class.to_s.blue} - done #{c.to_s.red} with #{class_results.size.to_s.green} results")
    result += class_results
  end

  return result
end

#represent_result(result) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/weather_fetcher/fetcher.rb', line 34

def represent_result(result)
  puts result.inspect
  data = result.sort{|r,s| r.time_from <=> s.time_from}
  data.each do |d|
    puts "#{d.provider} #{d.time_from} #{d.temperature} #{d.wind}"
  end
end