Class: Usps::Support::Models::Toast
- Inherits:
-
Object
- Object
- Usps::Support::Models::Toast
- Defined in:
- lib/usps/support/models/toast.rb
Overview
Toast constructor
Defined Under Namespace
Modules: Reserved
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#id ⇒ Object
Returns the value of attribute id.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #broadcast! ⇒ Object
- #dismiss! ⇒ Object
-
#initialize(options) ⇒ Toast
constructor
A new instance of Toast.
- #to_h ⇒ Object
- #to_json(*_) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(options) ⇒ Toast
Returns a new instance of Toast.
21 22 23 24 25 26 27 |
# File 'lib/usps/support/models/toast.rb', line 21 def initialize() @type = [:type] || :NOTICE @title = [:title] @body = [:body] @timeout = [:timeout] || 4_000 @id = [:id] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/usps/support/models/toast.rb', line 7 def body @body end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/usps/support/models/toast.rb', line 7 def id @id end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/usps/support/models/toast.rb', line 7 def timeout @timeout end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/usps/support/models/toast.rb', line 7 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/usps/support/models/toast.rb', line 7 def type @type end |
Class Method Details
.error ⇒ Object
17 18 19 |
# File 'lib/usps/support/models/toast.rb', line 17 def self.error(**) new(type: :ERROR, **) end |
.notice ⇒ Object
13 14 15 |
# File 'lib/usps/support/models/toast.rb', line 13 def self.notice(**) new(type: :NOTICE, **) end |
.success ⇒ Object
9 10 11 |
# File 'lib/usps/support/models/toast.rb', line 9 def self.success(**) new(type: :SUCCESS, **) end |
Instance Method Details
#==(other) ⇒ Object
54 |
# File 'lib/usps/support/models/toast.rb', line 54 def ==(other) = to_h == other.to_h |
#broadcast! ⇒ Object
29 30 31 |
# File 'lib/usps/support/models/toast.rb', line 29 def broadcast! BroadcastToastChannel.broadcast!(title, body, timeout:, type:, id:) end |
#dismiss! ⇒ Object
33 34 35 |
# File 'lib/usps/support/models/toast.rb', line 33 def dismiss! BroadcastToastChannel.dismiss!(id) end |
#to_h ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/usps/support/models/toast.rb', line 44 def to_h { type: type || :NOTICE, title:, body:, timeout:, id: } end |
#to_json(*_) ⇒ Object
56 57 58 59 60 |
# File 'lib/usps/support/models/toast.rb', line 56 def to_json(*_) validate! JSON.dump(to_h) end |
#to_s ⇒ Object Also known as: inspect
37 38 39 40 41 |
# File 'lib/usps/support/models/toast.rb', line 37 def to_s attributes = to_h.map { |key, value| "@#{key}=#{value.inspect}" }.join(' ') "#<Toast #{attributes}>" end |