Module: EorzeaWeather

Defined in:
lib/eorzea_weather/calculator.rb,
lib/eorzea_weather.rb,
lib/eorzea_weather/zone.rb,
lib/eorzea_weather/locale.rb,
lib/eorzea_weather/version.rb,
lib/eorzea_weather/localizer.rb,
lib/eorzea_weather/data/zones.rb,
lib/eorzea_weather/data/locales.rb,
lib/eorzea_weather/data/weathers.rb

Overview

Defined Under Namespace

Modules: Data Classes: Calculator, Locale, Localizer, Zone

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.find(weather, zone, time: Time.now, max_attempts: 60, count: 1) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/eorzea_weather.rb', line 44

def self.find(weather, zone, time: Time.now, max_attempts: 60, count: 1)
  weather = self.weather(weather)

  result = []
  forecast = self.forecast(zone, time)
  max_attempts.times do
    if forecast.weather == weather
      result << forecast
    end
    forecast = forecast.succ
  end

  result
end

.find_next(weather, zone, time: Time.now, max_attempts: 60) ⇒ Object



40
41
42
# File 'lib/eorzea_weather.rb', line 40

def self.find_next(weather, zone, time: Time.now, max_attempts: 60)
  find(weather, zone, time: time, max_attempts: max_attempts, count: 1)[0]
end

.forecast(zone, time = Time.now) ⇒ Object



59
60
61
# File 'lib/eorzea_weather.rb', line 59

def self.forecast(zone, time = Time.now)
  Calculator.new(self.zone(zone), time)
end

.forecasts(zone, time: Time.now, count: 6) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/eorzea_weather.rb', line 63

def self.forecasts(zone, time: Time.now, count: 6)
  [forecast(zone, time)].tap do |result|
    [0, count - 1].max.times do
      result << result.last.succ
    end
  end
end

.history(zone, time: Time.now, count: 6) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/eorzea_weather.rb', line 71

def self.history(zone, time: Time.now, count: 6)
  [forecast(zone, time)].tap do |result|
    [0, count - 1].max.times do
      result << result.last.prev
    end
  end.reverse
end

.weather(o) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eorzea_weather.rb', line 27

def self.weather(o)
  if o.kind_of?(String)
    o = Data::Locales::WEATHER_MAP[o] || o
    o = o.to_sym
  end
  if Data::Weathers::LIST.include?(o)
    return o
  else
    raise KeyError, "#{o} is not valid weather"
  end
end

.zone(o) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/eorzea_weather.rb', line 15

def self.zone(o)
  case o
  when Zone
    o
  when String
    o = Data::Locales::ZONE_MAP[o] || o
    Data::Zones::MAP.fetch o.to_sym
  else
    Data::Zones::MAP.fetch o.to_sym
  end
end

.zonesObject



11
12
13
# File 'lib/eorzea_weather.rb', line 11

def self.zones
  Data::Zones::MAP
end