Class: EorzeaWeather::Calculator
- Inherits:
-
Object
- Object
- EorzeaWeather::Calculator
- Defined in:
- lib/eorzea_weather/calculator.rb
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Instance Method Summary collapse
-
#days ⇒ Object
Number of days passed in Eorzea (1 eorzean day is 4200 seconds in local time).
- #end_hour ⇒ Object
- #end_time ⇒ Object
-
#hour ⇒ Object
Eorzean Hour (1 eorzean hour is 175 seconds in local time).
-
#initialize(zone, time) ⇒ Calculator
constructor
A new instance of Calculator.
- #inspect ⇒ Object
- #prev ⇒ Object
- #rate ⇒ Object
- #start_hour ⇒ Object
- #start_time ⇒ Object
- #succ ⇒ Object
- #weather ⇒ Object
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
#time ⇒ Object (readonly)
Returns the value of attribute time.
19 20 21 |
# File 'lib/eorzea_weather/calculator.rb', line 19 def time @time end |
#zone ⇒ Object (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
#days ⇒ Object
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_hour ⇒ Object
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_time ⇒ Object
33 34 35 |
# File 'lib/eorzea_weather/calculator.rb', line 33 def end_time EorzeaTime.new(end_hour * 3600).next_occurrence(time: @time) end |
#hour ⇒ Object
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 |
#inspect ⇒ Object
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 |
#prev ⇒ Object
11 12 13 |
# File 'lib/eorzea_weather/calculator.rb', line 11 def prev self.class.new(@zone, start_time - 1) end |
#rate ⇒ Object
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_hour ⇒ Object
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_time ⇒ Object
29 30 31 |
# File 'lib/eorzea_weather/calculator.rb', line 29 def start_time EorzeaTime.new(start_hour * 3600).last_occurrence(time: @time) end |
#succ ⇒ Object
15 16 17 |
# File 'lib/eorzea_weather/calculator.rb', line 15 def succ self.class.new(@zone, end_time + 1) end |
#weather ⇒ Object
25 26 27 |
# File 'lib/eorzea_weather/calculator.rb', line 25 def weather @weather ||= @zone.find_rate(rate) end |