Module: Sekki24::SeventyTwoKou
- Defined in:
- lib/sekki24/seventy_two_kou.rb
Class Method Summary collapse
- .clear_cache! ⇒ Object
- .current(time, tz:, precision:) ⇒ Object
- .fetch(year, ordinal, tz:, precision:) ⇒ Object
- .next_kou(time, tz:, precision:) ⇒ Object
- .previous(time, tz:, precision:) ⇒ Object
- .year(year, tz:, precision:) ⇒ Object
Class Method Details
.clear_cache! ⇒ Object
45 46 47 48 49 50 |
# File 'lib/sekki24/seventy_two_kou.rb', line 45 def clear_cache! @cache_mutex.synchronize do @year_cache.clear @candidate_cache.clear end end |
.current(time, tz:, precision:) ⇒ Object
30 31 32 33 |
# File 'lib/sekki24/seventy_two_kou.rb', line 30 def current(time, tz:, precision:) (time, tz, precision).select { |entry| entry.time <= time }.max || raise(RangeError, "no current kou in the supported range") end |
.fetch(year, ordinal, tz:, precision:) ⇒ Object
25 26 27 28 |
# File 'lib/sekki24/seventy_two_kou.rb', line 25 def fetch(year, ordinal, tz:, precision:) definition = KouNames.fetch(ordinal) self.year(year, tz: tz, precision: precision).find { |entry| entry.ordinal == definition.ordinal } end |
.next_kou(time, tz:, precision:) ⇒ Object
35 36 37 38 |
# File 'lib/sekki24/seventy_two_kou.rb', line 35 def next_kou(time, tz:, precision:) (time, tz, precision).select { |entry| entry.time > time }.min || raise(RangeError, "no next kou in the supported range") end |
.previous(time, tz:, precision:) ⇒ Object
40 41 42 43 |
# File 'lib/sekki24/seventy_two_kou.rb', line 40 def previous(time, tz:, precision:) (time, tz, precision).select { |entry| entry.time < time }.max || raise(RangeError, "no previous kou in the supported range") end |
.year(year, tz:, precision:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sekki24/seventy_two_kou.rb', line 13 def year(year, tz:, precision:) calendar_year = validate_year(year) mode = normalize_precision(precision) solar = Solar.model(mode) cache_key = [calendar_year, TimeScale.timezone_key(tz), mode].freeze cached = @cache_mutex.synchronize { @year_cache[cache_key] } return cached if cached calculated = calculate_year(calendar_year, tz, mode, solar) @cache_mutex.synchronize { @year_cache[cache_key] ||= calculated } end |