Class: Smith::Tool::CallBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/tool/call_batch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size:, counts:) ⇒ CallBatch

Returns a new instance of CallBatch.



40
41
42
43
44
# File 'lib/smith/tool/call_batch.rb', line 40

def initialize(size:, counts:)
  @size = size
  @counts = counts
  freeze
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



6
7
8
# File 'lib/smith/tool/call_batch.rb', line 6

def counts
  @counts
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/smith/tool/call_batch.rb', line 6

def size
  @size
end

Class Method Details

.coerce(value, exact:) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
# File 'lib/smith/tool/call_batch.rb', line 8

def self.coerce(value, exact:)
  return from_size(value, exact:) if value.is_a?(Integer)
  raise ArgumentError, "tool call batch size must be a positive integer" unless value.is_a?(Array)

  names = value.map { canonical_tool_name(_1) }
  validate_size!(names.length)
  new(size: names.length, counts: names.tally.freeze)
end