Class: Pikuri::Thunderbird::CalendarRead

Inherits:
Pikuri::Tool
  • Object
show all
Defined in:
lib/pikuri/thunderbird/calendar_read.rb

Overview

The thunderbird_calendar_read tool — the read half of the calendar search→read pair. Given an event_id from thunderbird_calendar_search, returns the full event: when, where, status, attendees (with RSVP), and description. Inbound-only.

Sharing: P_shared_locked — no state of its own, and the Calendar backend it queries locks; see that class's == Sharing.

Constant Summary collapse

ATTENDEE_CAP =

Returns max attendees listed individually; beyond it the list truncates to a per-status tally so a 169-guest all-hands can't flood the observation.

Returns:

  • (Integer)

    max attendees listed individually; beyond it the list truncates to a per-status tally so a 169-guest all-hands can't flood the observation.

40
STATUS_LABELS =

Returns PARTSTAT → human RSVP word.

Returns:

  • (Hash{String=>String})

    PARTSTAT → human RSVP word.

{
  'ACCEPTED' => 'accepted', 'DECLINED' => 'declined',
  'TENTATIVE' => 'tentative', 'NEEDS-ACTION' => 'no reply'
}.freeze
DESCRIPTION =

Returns opencode-shape description.

Returns:

  • (String)

    opencode-shape description.

<<~DESC
  Read one Thunderbird calendar event in full (title, when, where, status, attendees with their RSVP, and description).

  Usage:
  - Pass the id from a thunderbird_calendar_search result.
DESC

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend:) ⇒ CalendarRead

Parameters:

  • backend (Calendar)

    the calendar backend.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pikuri/thunderbird/calendar_read.rb', line 34

def initialize(backend:)
  @backend = backend
  super(
    name: 'thunderbird_calendar_read',
    description: DESCRIPTION,
    parameters: Parameters.build { |p|
      p.required_string :event_id, 'The id from a search result, e.g. "abc123-uid".'
    },
    execute: lambda { |event_id:|
      CalendarRead.run_read(backend: @backend, event_id:)
    },
    trifecta_legs: Pikuri::Thunderbird::INBOUND_LEGS
  )
end

Class Method Details

.run_read(backend:, event_id:) ⇒ String

Returns formatted event or "Error: …".

Returns:

  • (String)

    formatted event or "Error: …".



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pikuri/thunderbird/calendar_read.rb', line 50

def self.run_read(backend:, event_id:)
  ev = backend.read(event_id:)
  return "Error: no event found with id #{event_id.inspect}." unless ev

  desc = ev[:description].to_s.strip
  [
    "Title: #{ev[:title]}",
    "When: #{DateHelpers.when_label(ev)}",
    "Where: #{ev[:location].to_s.strip.empty? ? '(none)' : ev[:location].strip}",
    "Status: #{ev[:status] || '(none)'}",
    *attendee_lines(ev[:attendees]),
    '',
    desc.empty? ? '(no description)' : desc
  ].join("\n")
end