Class: OpenCensus::Trace::TruncatableString

Inherits:
Object
  • Object
show all
Defined in:
lib/opencensus/trace/truncatable_string.rb

Overview

A string that might be shortened to a specified length.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, truncated_byte_count: 0) ⇒ TruncatableString

Create an empty TruncatableString object.



46
47
48
49
# File 'lib/opencensus/trace/truncatable_string.rb', line 46

def initialize value, truncated_byte_count: 0
  @value = value
  @truncated_byte_count = truncated_byte_count
end

Instance Attribute Details

#truncated_byte_countInteger (readonly)

The number of bytes removed from the original string. If this value is 0, then the string was not shortened.

Returns:

  • (Integer)


39
40
41
# File 'lib/opencensus/trace/truncatable_string.rb', line 39

def truncated_byte_count
  @truncated_byte_count
end

#valueString (readonly)

The shortened string. For example, if the original string was 500 bytes long and the limit of the string was 128 bytes, then this value contains the first 128 bytes of the 500-byte string. Note that truncation always happens on a character boundary, to ensure that a truncated string is still valid UTF-8. Because it may contain multi-byte characters, the size of the truncated string may be less than the truncation limit.

Returns:

  • (String)


31
32
33
# File 'lib/opencensus/trace/truncatable_string.rb', line 31

def value
  @value
end

Instance Method Details

#to_sObject

Override the default to_s implementation.



56
57
58
# File 'lib/opencensus/trace/truncatable_string.rb', line 56

def to_s
  @value
end