Class: Slk::Models::ScheduledStatus
- Inherits:
-
Data
- Object
- Data
- Slk::Models::ScheduledStatus
- 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
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#date_expire ⇒ Object
readonly
Returns the value of attribute date_expire.
-
#date_scheduled ⇒ Object
readonly
Returns the value of attribute date_scheduled.
-
#dnd ⇒ Object
readonly
Returns the value of attribute dnd.
-
#emoji ⇒ Object
readonly
Returns the value of attribute emoji.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #ends_at ⇒ Object
- #starts_at ⇒ Object
- #to_s ⇒ Object
-
#window ⇒ Object
Human-readable window; the end date is only repeated when it differs from the start date, which makes multi-day windows obvious.
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def active @active end |
#date_expire ⇒ Object (readonly)
Returns the value of attribute date_expire
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def date_expire @date_expire end |
#date_scheduled ⇒ Object (readonly)
Returns the value of attribute date_scheduled
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def date_scheduled @date_scheduled end |
#dnd ⇒ Object (readonly)
Returns the value of attribute dnd
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def dnd @dnd end |
#emoji ⇒ Object (readonly)
Returns the value of attribute emoji
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def emoji @emoji end |
#id ⇒ Object (readonly)
Returns the value of attribute id
9 10 11 |
# File 'lib/slk/models/scheduled_status.rb', line 9 def id @id end |
#text ⇒ Object (readonly)
Returns the value of attribute 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_at ⇒ Object
44 |
# File 'lib/slk/models/scheduled_status.rb', line 44 def ends_at = date_expire.positive? ? Time.at(date_expire) : nil |
#starts_at ⇒ Object
43 |
# File 'lib/slk/models/scheduled_status.rb', line 43 def starts_at = date_scheduled.positive? ? Time.at(date_scheduled) : nil |
#to_s ⇒ Object
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 |
#window ⇒ Object
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 |