Class: Kindergarten::Event
- Inherits:
-
Object
- Object
- Kindergarten::Event
- Defined in:
- lib/kindergarten/event.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#purpose ⇒ Object
readonly
Returns the value of attribute purpose.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, purpose, payload) ⇒ Event
constructor
A new instance of Event.
- #to_json ⇒ Object
Constructor Details
#initialize(name, purpose, payload) ⇒ Event
Returns a new instance of Event.
20 21 22 23 24 |
# File 'lib/kindergarten/event.rb', line 20 def initialize(name, purpose, payload) @name = name || raise("An event must have a name") @purpose = purpose || raise("An event must have a purpose") @payload = payload end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/kindergarten/event.rb', line 5 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/kindergarten/event.rb', line 5 def payload @payload end |
#purpose ⇒ Object (readonly)
Returns the value of attribute purpose.
5 6 7 |
# File 'lib/kindergarten/event.rb', line 5 def purpose @purpose end |
Class Method Details
.load(hash) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kindergarten/event.rb', line 7 def self.load(hash) if hash.is_a?(String) hash = begin Rufus::Json.decode(hash) rescue => ex raise ArgumentError.new("The provided string could not be decoded as JSON") end end hash.symbolize_keys! self.new(hash[:name], hash[:purpose], hash[:payload]) end |
Instance Method Details
#to_json ⇒ Object
26 27 28 29 30 |
# File 'lib/kindergarten/event.rb', line 26 def to_json Rufus::Json.encode( :name => @name, :purpose => @purpose, :payload => @payload ) end |