Class: Acta::Actor
- Inherits:
-
Object
- Object
- Acta::Actor
- Defined in:
- lib/acta/actor.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(type:, id: nil, source: nil, metadata: {}) ⇒ Actor
constructor
A new instance of Actor.
- #to_h ⇒ Object
Constructor Details
#initialize(type:, id: nil, source: nil, metadata: {}) ⇒ Actor
Returns a new instance of Actor.
7 8 9 10 11 12 13 14 |
# File 'lib/acta/actor.rb', line 7 def initialize(type:, id: nil, source: nil, metadata: {}) raise ArgumentError, "Acta::Actor type must be a non-empty string" if type.nil? || type.to_s.empty? @type = type.to_s @id = id @source = source @metadata = end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/acta/actor.rb', line 5 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/acta/actor.rb', line 5 def @metadata end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/acta/actor.rb', line 5 def source @source end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/acta/actor.rb', line 5 def type @type end |
Class Method Details
.from_h(hash) ⇒ Object
29 30 31 32 |
# File 'lib/acta/actor.rb', line 29 def self.from_h(hash) hash = hash.transform_keys(&:to_sym) new(type: hash[:type], id: hash[:id], source: hash[:source], metadata: hash[:metadata] || {}) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
20 21 22 |
# File 'lib/acta/actor.rb', line 20 def ==(other) other.is_a?(self.class) && to_h == other.to_h end |
#hash ⇒ Object
25 26 27 |
# File 'lib/acta/actor.rb', line 25 def hash to_h.hash end |
#to_h ⇒ Object
16 17 18 |
# File 'lib/acta/actor.rb', line 16 def to_h { type:, id:, source:, metadata: } end |