Class: Acta::Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/acta/actor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id: nil, source: nil, metadata: {}) ⇒ Actor

Returns a new instance of Actor.

Raises:

  • (ArgumentError)


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

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/acta/actor.rb', line 5

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/acta/actor.rb', line 5

def 
  @metadata
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/acta/actor.rb', line 5

def source
  @source
end

#typeObject (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

#hashObject



25
26
27
# File 'lib/acta/actor.rb', line 25

def hash
  to_h.hash
end

#to_hObject



16
17
18
# File 'lib/acta/actor.rb', line 16

def to_h
  { type:, id:, source:, metadata: }
end