Class: GraphAgent::Channels::BinaryOperatorAggregate
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- GraphAgent::Channels::BinaryOperatorAggregate
show all
- Defined in:
- lib/graph_agent/channels/binary_operator_aggregate.rb
Constant Summary
Constants inherited
from BaseChannel
GraphAgent::Channels::BaseChannel::MISSING
Instance Attribute Summary collapse
Attributes inherited from BaseChannel
#key
Instance Method Summary
collapse
Methods inherited from BaseChannel
#consume, #finish
Constructor Details
#initialize(operator:, key: "", default: MISSING) ⇒ BinaryOperatorAggregate
Returns a new instance of BinaryOperatorAggregate.
8
9
10
11
12
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 8
def initialize(operator:, key: "", default: MISSING)
super(key: key)
@operator = operator
@value = default
end
|
Instance Attribute Details
#operator ⇒ Object
Returns the value of attribute operator.
6
7
8
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 6
def operator
@operator
end
|
Instance Method Details
#available? ⇒ Boolean
35
36
37
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 35
def available?
!@value.equal?(MISSING)
end
|
#checkpoint ⇒ Object
39
40
41
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 39
def checkpoint
@value
end
|
#copy ⇒ Object
49
50
51
52
53
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 49
def copy
ch = self.class.new(operator: @operator, key: key)
ch.instance_variable_set(:@value, @value)
ch
end
|
#from_checkpoint(checkpoint) ⇒ Object
43
44
45
46
47
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 43
def from_checkpoint(checkpoint)
ch = self.class.new(operator: @operator, key: key)
ch.instance_variable_set(:@value, checkpoint.equal?(MISSING) ? MISSING : checkpoint)
ch
end
|
#get ⇒ Object
14
15
16
17
18
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 14
def get
raise EmptyChannelError.new("Channel '#{key}' is empty") if @value.equal?(MISSING)
@value
end
|
#update(values) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/graph_agent/channels/binary_operator_aggregate.rb', line 20
def update(values)
return false if values.empty?
if @value.equal?(MISSING)
@value = values.first
values = values[1..]
end
values.each do |value|
@value = @operator.call(@value, value)
end
true
end
|