Class: Slk::Models::Status

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#emojiObject (readonly)

Returns the value of attribute emoji

Returns:

  • (Object)

    the current value of emoji



5
6
7
# File 'lib/slk/models/status.rb', line 5

def emoji
  @emoji
end

#expirationObject (readonly)

Returns the value of attribute expiration

Returns:

  • (Object)

    the current value of expiration



5
6
7
# File 'lib/slk/models/status.rb', line 5

def expiration
  @expiration
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



5
6
7
# File 'lib/slk/models/status.rb', line 5

def text
  @text
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/slk/models/status.rb', line 17

def empty?
  text.empty? && emoji.empty?
end

#expiration_timeObject



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/slk/models/status.rb', line 25

def expired?
  expires? && expiration < Time.now.to_i
end

#expires?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/slk/models/status.rb', line 21

def expires?
  expiration.positive?
end

#time_remainingObject



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_sObject



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