Module: TraceViz::Utils::Format::ValueTruncator

Defined in:
lib/trace_viz/utils/format/value_truncator.rb

Constant Summary collapse

DEFAULT_LENGTH =
-1
VALID_DIRECTIONS =
[:start, :end].freeze

Class Method Summary collapse

Class Method Details

.truncate(value, length: DEFAULT_LENGTH, direction: :end, hash_length: DEFAULT_LENGTH) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/trace_viz/utils/format/value_truncator.rb', line 11

def truncate(value, length: DEFAULT_LENGTH, direction: :end, hash_length: DEFAULT_LENGTH)
  validate_params(length, direction, hash_length)

  # Skip truncation if length is not positive
  return value unless length.positive?

  opts = {
    value: value,
    length: length,
    direction: direction,
    hash_length: hash_length,
  }

  case value
  when String then truncate_string(opts)
  when Array then truncate_array(opts)
  when Hash then truncate_hash(opts)
  else truncate_object(opts)
  end
end