module ClockTick
ClockTick — minute keys, due checks, and tick message assembly. Public: minute_key, due_for_tick?, mark_tick, channel_timezone, build_tick_message, timezone_short_label, tick_channel Depends: ClockFlip, ClockFlipMeaning, ClockReport, ClockSegment, RabbotDb Tests: test/plugins/clock_test.rb
Constants
- DEFAULT_LINES
Public Instance Methods
Source
# File lib/clock/tick.rb, line 38 def build_tick_message(now:, utc_offset:, lines:, meaning_lookup: ClockFlipMeaning, rng: Random.new, lookup_now: nil) hour, minute, local = ClockFlip.local_parts(now: now, utc_offset: utc_offset) time_label = ClockFlip.format_time(hour, minute) primary_flip_word = ClockFlip.upside_down_word(hour, minute) led_lines = ClockSegment.render(hour, minute, lines: lines) lookup_kwargs = { time_label: time_label, hour: hour, minute: minute, rng: rng } lookup_kwargs[:now] = lookup_now if lookup_now lookup_kwargs[:spread_count] = lines meaning = if ClockFlip.flip_word?(primary_flip_word) meaning_lookup.lookup_with_hint(**lookup_kwargs) else { lines: [], hint: nil, flip_word: primary_flip_word } end flip_word = meaning[:flip_word] || primary_flip_word tz_label = timezone_short_label(local) ClockReport.format_tick( time_label: time_label, tz_label: tz_label, flip_word: flip_word, led_lines: led_lines, association_lines: meaning[:lines], meaning_hint: meaning[:hint], line_budget: lines ) end
Source
# File lib/clock/tick.rb, line 33 def channel_timezone(network:, channel:, store: RabbotDb, now: Time.now) require_relative "../../plugins/reminder" Reminder.reminder_timezone(network: network, channel: channel, store: store, now: now) end
Source
# File lib/clock/tick.rb, line 23 def due_for_tick?(state, now:, utc_offset:) return false unless state["enabled"] minute_key(now, utc_offset: utc_offset) != state["last_minute"].to_s end
Source
# File lib/clock/tick.rb, line 29 def mark_tick(state, now:, utc_offset:) state.merge("last_minute" => minute_key(now, utc_offset: utc_offset)) end
Source
# File lib/clock/tick.rb, line 19 def minute_key(now, utc_offset:) now.getlocal(utc_offset).strftime("%H:%M") end
Source
# File lib/clock/tick.rb, line 76 def tick_channel(state:, now:, utc_offset:) return nil unless due_for_tick?(state, now: now, utc_offset: utc_offset) text = build_tick_message(now: now, utc_offset: utc_offset, lines: state["lines"]) { text: text, state: mark_tick(state, now: now, utc_offset: utc_offset) } end
Source
# File lib/clock/tick.rb, line 70 def timezone_short_label(local_time) local_time.strftime("%Z").strip rescue StandardError "" end