Class: Tama::Neural::OperationParams

Inherits:
Data
  • Object
show all
Defined in:
lib/tama/neural/operation_params.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain_ids:, node_type: nil) ⇒ OperationParams

Returns a new instance of OperationParams.



6
7
8
9
10
11
12
13
14
15
# File 'lib/tama/neural/operation_params.rb', line 6

def initialize(chain_ids:, node_type: nil)
  unless chain_ids.is_a?(Array) && !chain_ids.empty? && chain_ids.all? { |id| id.is_a?(String) && !id.empty? }
    raise Error::ValidationError.new("chain_ids must contain at least one chain ID", errors: {chain_ids: "must contain non-empty strings"})
  end
  unless node_type.nil? || node_type.is_a?(String)
    raise Error::ValidationError.new("node_type must be a string", errors: {node_type: "must be a string"})
  end

  super
end

Instance Attribute Details

#chain_idsObject (readonly)

Returns the value of attribute chain_ids

Returns:

  • (Object)

    the current value of chain_ids



5
6
7
# File 'lib/tama/neural/operation_params.rb', line 5

def chain_ids
  @chain_ids
end

#node_typeObject (readonly)

Returns the value of attribute node_type

Returns:

  • (Object)

    the current value of node_type



5
6
7
# File 'lib/tama/neural/operation_params.rb', line 5

def node_type
  @node_type
end

Class Method Details

.parse(value) ⇒ Object



17
18
19
20
# File 'lib/tama/neural/operation_params.rb', line 17

def self.parse(value)
  data = Params.hash(value, "operation")
  new(chain_ids: data["chain_ids"], node_type: data["node_type"])
end

Instance Method Details

#to_hObject



22
23
24
# File 'lib/tama/neural/operation_params.rb', line 22

def to_h
  {"chain_ids" => chain_ids}.tap { |body| body["node_type"] = node_type unless node_type.nil? }
end