Class: Slk::Models::Status
- Inherits:
-
Data
- Object
- Data
- Slk::Models::Status
- Defined in:
- lib/slk/models/status.rb
Instance Attribute Summary collapse
-
#emoji ⇒ Object
readonly
Returns the value of attribute emoji.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #expiration_time ⇒ Object
- #expired? ⇒ Boolean
- #expires? ⇒ Boolean
-
#initialize(text: '', emoji: '', expiration: 0) ⇒ Status
constructor
A new instance of Status.
- #time_remaining ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(text: '', emoji: '', expiration: 0) ⇒ Status
Returns a new instance of Status.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/slk/models/status.rb', line 6 def initialize(text: '', emoji: '', expiration: 0) exp_val = expiration.to_i exp_val = 0 if exp_val.negative? # Normalize invalid negative expirations super( text: text.to_s.freeze, emoji: emoji.to_s.freeze, expiration: exp_val ) end |
Instance Attribute Details
#emoji ⇒ Object (readonly)
Returns the value of attribute emoji
5 6 7 |
# File 'lib/slk/models/status.rb', line 5 def emoji @emoji end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration
5 6 7 |
# File 'lib/slk/models/status.rb', line 5 def expiration @expiration end |
#text ⇒ Object (readonly)
Returns the value of attribute text
5 6 7 |
# File 'lib/slk/models/status.rb', line 5 def text @text end |
Instance Method Details
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/slk/models/status.rb', line 17 def empty? text.empty? && emoji.empty? end |
#expiration_time ⇒ Object
36 37 38 39 40 |
# File 'lib/slk/models/status.rb', line 36 def expiration_time return nil unless expires? Time.at(expiration) end |
#expired? ⇒ Boolean
25 26 27 |
# File 'lib/slk/models/status.rb', line 25 def expired? expires? && expiration < Time.now.to_i end |
#expires? ⇒ Boolean
21 22 23 |
# File 'lib/slk/models/status.rb', line 21 def expires? expiration.positive? end |
#time_remaining ⇒ Object
29 30 31 32 33 34 |
# File 'lib/slk/models/status.rb', line 29 def time_remaining return nil unless expires? remaining = expiration - Time.now.to_i remaining.positive? ? Duration.new(seconds: remaining) : nil end |
#to_s ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/slk/models/status.rb', line 42 def to_s return '(no status)' if empty? parts = [] parts << emoji unless emoji.empty? parts << text unless text.empty? if (remaining = time_remaining) parts << "(#{remaining})" end parts.join(' ') end |