Class: Slk::Models::ScheduledStatus

Inherits:
Data
  • Object
show all
Defined in:
lib/slk/models/scheduled_status.rb

Overview

A status queued to turn on later, from users.customStatus.list.

Slack derives duration server-side from the window, so it is not modelled here — the window itself is the source of truth.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active

Returns:

  • (Object)

    the current value of active



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def active
  @active
end

#date_expireObject (readonly)

Returns the value of attribute date_expire

Returns:

  • (Object)

    the current value of date_expire



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def date_expire
  @date_expire
end

#date_scheduledObject (readonly)

Returns the value of attribute date_scheduled

Returns:

  • (Object)

    the current value of date_scheduled



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def date_scheduled
  @date_scheduled
end

#dndObject (readonly)

Returns the value of attribute dnd

Returns:

  • (Object)

    the current value of dnd



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def dnd
  @dnd
end

#emojiObject (readonly)

Returns the value of attribute emoji

Returns:

  • (Object)

    the current value of emoji



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def emoji
  @emoji
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def id
  @id
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



9
10
11
# File 'lib/slk/models/scheduled_status.rb', line 9

def text
  @text
end

Class Method Details

.from_api(data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slk/models/scheduled_status.rb', line 10

def self.from_api(data)
  validate!(data)

  new(
    id: data['id'].to_s,
    text: data['text'].to_s,
    emoji: data['emoji'].to_s,
    date_scheduled: data['date_scheduled'].to_i,
    date_expire: data['date_expire'].to_i,
    dnd: truthy?(data['is_dnd']),
    active: truthy?(data['is_active'])
  )
end

Instance Method Details

#ends_atObject



44
# File 'lib/slk/models/scheduled_status.rb', line 44

def ends_at = date_expire.positive? ? Time.at(date_expire) : nil

#starts_atObject



43
# File 'lib/slk/models/scheduled_status.rb', line 43

def starts_at = date_scheduled.positive? ? Time.at(date_scheduled) : nil

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/slk/models/scheduled_status.rb', line 46

def to_s
  span = window
  [
    emoji,
    text,
    span.empty? ? '' : "(#{span})",
    ('[dnd]' if dnd),
    # Slack marks the one that has already turned on. Worth showing: it
    # is the difference between "will happen" and "is happening".
    ('[active]' if active)
  ].reject { |part| part.to_s.empty? }.join(' ')
end

#windowObject

Human-readable window; the end date is only repeated when it differs from the start date, which makes multi-day windows obvious.



61
62
63
64
65
66
67
68
# File 'lib/slk/models/scheduled_status.rb', line 61

def window
  dated = '%a %b %-d %-l:%M%P'
  start_time = starts_at or return ''
  formatted = start_time.strftime(dated)
  finish = ends_at or return formatted

  "#{formatted} -> #{finish.strftime(same_day?(start_time, finish) ? '%-l:%M%P' : dated)}"
end