Class: Slk::Models::Preset
- Inherits:
-
Data
- Object
- Data
- Slk::Models::Preset
- Defined in:
- lib/slk/models/preset.rb
Instance Attribute Summary collapse
-
#dnd ⇒ Object
readonly
Returns the value of attribute dnd.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#emoji ⇒ Object
readonly
Returns the value of attribute emoji.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#presence ⇒ Object
readonly
Returns the value of attribute presence.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #clears_status? ⇒ Boolean
- #duration_value ⇒ Object
-
#initialize(name:, text: '', emoji: '', duration: '0', presence: '', dnd: '') ⇒ Preset
constructor
rubocop:disable Metrics/ParameterLists.
- #sets_dnd? ⇒ Boolean
- #sets_presence? ⇒ Boolean
-
#to_h ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #to_s ⇒ Object
Constructor Details
#initialize(name:, text: '', emoji: '', duration: '0', presence: '', dnd: '') ⇒ Preset
rubocop:disable Metrics/ParameterLists
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/slk/models/preset.rb', line 18 def initialize(name:, text: '', emoji: '', duration: '0', presence: '', dnd: '') validate_name!(name) validate_duration!(duration) super( name: name.to_s.strip.freeze, text: text.to_s.freeze, emoji: emoji.to_s.freeze, duration: duration.to_s.freeze, presence: presence.to_s.freeze, dnd: dnd.to_s.freeze ) end |
Instance Attribute Details
#dnd ⇒ Object (readonly)
Returns the value of attribute dnd
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def dnd @dnd end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def duration @duration end |
#emoji ⇒ Object (readonly)
Returns the value of attribute emoji
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def emoji @emoji end |
#name ⇒ Object (readonly)
Returns the value of attribute name
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def name @name end |
#presence ⇒ Object (readonly)
Returns the value of attribute presence
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def presence @presence end |
#text ⇒ Object (readonly)
Returns the value of attribute text
5 6 7 |
# File 'lib/slk/models/preset.rb', line 5 def text @text end |
Class Method Details
.from_hash(name, data) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/slk/models/preset.rb', line 6 def self.from_hash(name, data) new( name: name, text: data['text'] || '', emoji: data['emoji'] || '', duration: data['duration'] || '0', presence: data['presence'] || '', dnd: data['dnd'] || '' ) end |
Instance Method Details
#clears_status? ⇒ Boolean
46 47 48 |
# File 'lib/slk/models/preset.rb', line 46 def clears_status? text.empty? && emoji.empty? end |
#duration_value ⇒ Object
34 35 36 |
# File 'lib/slk/models/preset.rb', line 34 def duration_value Duration.parse(duration) end |
#sets_dnd? ⇒ Boolean
42 43 44 |
# File 'lib/slk/models/preset.rb', line 42 def sets_dnd? !dnd.empty? end |
#sets_presence? ⇒ Boolean
38 39 40 |
# File 'lib/slk/models/preset.rb', line 38 def sets_presence? !presence.empty? end |
#to_h ⇒ Object
rubocop:enable Metrics/ParameterLists
30 31 32 |
# File 'lib/slk/models/preset.rb', line 30 def to_h { 'text' => text, 'emoji' => emoji, 'duration' => duration, 'presence' => presence, 'dnd' => dnd } end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/slk/models/preset.rb', line 50 def to_s "#{name}: #{build_parts.join(' ')}" end |