Sha256: 2bb9b622bedf22c347befa7859cc16aea250c801260fa8292614221e629a52a5

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

# Copyright 2017 OpenCensus Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module OpenCensus
  module Trace
    ##
    # A string that might be shortened to a specified length.
    #
    class TruncatableString
      ##
      # 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.
      #
      # @return [String]
      #
      attr_reader :value

      ##
      # The number of bytes removed from the original string. If this value is
      # 0, then the string was not shortened.
      #
      # @return [Integer]
      #
      attr_reader :truncated_byte_count

      ##
      # Create an empty TruncatableString object.
      #
      # @private
      #
      def initialize value, truncated_byte_count: 0
        @value = value
        @truncated_byte_count = truncated_byte_count
      end

      ##
      # Override the default to_s implementation.
      #
      # @private
      #
      def to_s
        @value
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opencensus-0.3.1 lib/opencensus/trace/truncatable_string.rb
opencensus-0.3.0 lib/opencensus/trace/truncatable_string.rb
opencensus-0.2.2 lib/opencensus/trace/truncatable_string.rb
opencensus-0.2.1 lib/opencensus/trace/truncatable_string.rb
opencensus-0.2.0 lib/opencensus/trace/truncatable_string.rb
opencensus-0.1.0 lib/opencensus/trace/truncatable_string.rb