Class: EorzeaWeather::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/eorzea_weather/calculator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone, time) ⇒ Calculator

Returns a new instance of Calculator.



6
7
8
9
# File 'lib/eorzea_weather/calculator.rb', line 6

def initialize(zone, time)
  @zone = zone
  @time = time.utc
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



19
20
21
# File 'lib/eorzea_weather/calculator.rb', line 19

def time
  @time
end

#zoneObject (readonly)

Returns the value of attribute zone.



19
20
21
# File 'lib/eorzea_weather/calculator.rb', line 19

def zone
  @zone
end

Instance Method Details

#daysObject

Number of days passed in Eorzea (1 eorzean day is 4200 seconds in local time)



43
44
45
# File 'lib/eorzea_weather/calculator.rb', line 43

def days
  @days ||= @time.to_i / 4200
end

#end_hourObject



52
53
54
55
# File 'lib/eorzea_weather/calculator.rb', line 52

def end_hour
  # 0..7 => 8, 8..15 => 16, 16..23 => 0
  ((hour + 8) - (hour % 8)) % 24
end

#end_timeObject



33
34
35
# File 'lib/eorzea_weather/calculator.rb', line 33

def end_time
  EorzeaTime.new(end_hour * 3600).next_occurrence(time: @time)
end

#hourObject

Eorzean Hour (1 eorzean hour is 175 seconds in local time)



38
39
40
# File 'lib/eorzea_weather/calculator.rb', line 38

def hour
  @hour ||= @time.to_i / 175 % 24
end

#inspectObject



21
22
23
# File 'lib/eorzea_weather/calculator.rb', line 21

def inspect
  "#<#{self.class.name}: #{zone.id}, #{time} (#{start_hour}-#{end_hour}: #{weather})>"
end

#prevObject



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

def prev
  self.class.new(@zone, start_time - 1)
end

#rateObject



57
58
59
60
61
62
63
64
# File 'lib/eorzea_weather/calculator.rb', line 57

def rate
  @rate ||= begin
    base = (days * 0x64) + end_hour
    step1 = (base << 0xb & 0xffffffff) ^ base
    step2 = (step1 >> 8 & 0xffffffff) ^ step1
    step2 % 0x64
  end
end

#start_hourObject



47
48
49
50
# File 'lib/eorzea_weather/calculator.rb', line 47

def start_hour
  # 0..7 => 0, 8..15 => 8, 16..23 => 16
  hour - (hour % 8)
end

#start_timeObject



29
30
31
# File 'lib/eorzea_weather/calculator.rb', line 29

def start_time
  EorzeaTime.new(start_hour * 3600).last_occurrence(time: @time)
end

#succObject



15
16
17
# File 'lib/eorzea_weather/calculator.rb', line 15

def succ
  self.class.new(@zone, end_time + 1)
end

#weatherObject



25
26
27
# File 'lib/eorzea_weather/calculator.rb', line 25

def weather
  @weather ||= @zone.find_rate(rate)
end