Class: Phronomy::Agent::ContextSelectionUnit

Inherits:
Data
  • Object
show all
Defined in:
lib/phronomy/agent/context_selection_unit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**values) ⇒ ContextSelectionUnit

Returns a new instance of ContextSelectionUnit.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/phronomy/agent/context_selection_unit.rb', line 15

def initialize(**values)
  normalized = values.merge(
    unit_id: values.fetch(:unit_id).to_s.freeze,
    candidate_ids: Array(values[:candidate_ids]).map(&:to_s).freeze,
    dependency_unit_ids: Array(values[:dependency_unit_ids]).map(&:to_s).freeze,
    kind: values.fetch(:kind).to_sym,
    requirement: (values[:requirement] || :optional).to_sym,
    priority: Integer(values[:priority] || 0),
    sequence_range: Array(values[:sequence_range]).map { |v| Integer(v) }.freeze,
    metadata: Immutable.copy(values[:metadata] || {})
  )
  unless %i[protocol_required declared_required optional].include?(normalized[:requirement])
    raise ArgumentError, "unknown ContextSelectionUnit requirement: #{normalized[:requirement].inspect}"
  end
  unless normalized[:sequence_range].length == 2
    raise ArgumentError, "ContextSelectionUnit sequence_range must contain two integers"
  end

  super(**normalized)
  freeze
end

Instance Attribute Details

#candidate_idsObject (readonly)

Returns the value of attribute candidate_ids

Returns:

  • (Object)

    the current value of candidate_ids



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def candidate_ids
  @candidate_ids
end

#dependency_unit_idsObject (readonly)

Returns the value of attribute dependency_unit_ids

Returns:

  • (Object)

    the current value of dependency_unit_ids



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def dependency_unit_ids
  @dependency_unit_ids
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def kind
  @kind
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def 
  @metadata
end

#priorityObject (readonly)

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def priority
  @priority
end

#requirementObject (readonly)

Returns the value of attribute requirement

Returns:

  • (Object)

    the current value of requirement



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def requirement
  @requirement
end

#sequence_rangeObject (readonly)

Returns the value of attribute sequence_range

Returns:

  • (Object)

    the current value of sequence_range



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def sequence_range
  @sequence_range
end

#unit_idObject (readonly)

Returns the value of attribute unit_id

Returns:

  • (Object)

    the current value of unit_id



5
6
7
# File 'lib/phronomy/agent/context_selection_unit.rb', line 5

def unit_id
  @unit_id
end