<commit_before># -*- encoding: utf-8 -*-

module TTY
  class Text

    # A class responsible for text wrapping operations
    class Wrapping
      include Unicode

      attr_reader :text

      attr_reader :width

      attr_reader :indent

      # Initialize a Wrapping
      #
      # @param [String] text
      #   the text to be wrapped
      #
      # @overload new(text, value)
      #   wraps text at given value
      #
      #   @param [Integer] value
      #
      # @overload new(text, value, options)
      #   @param [Integer] value
      #   @param [Hash] options
      #   @option options [Symbol] :indent the indentation
      #
      # @api private
      def initialize(text, *args)
        options = Utils.extract_options!(args)
        @text    = text
        @width   = options.fetch(:width) { DEFAULT_WIDTH }
        @indent  = options.fetch(:indent) { 0 }
        @width   = args[0] unless args.empty?
      end

      # Wrap a text into lines no longer than width.
      #
      # @see TTY::Text#wrap
      #
      # @api private
      def wrap
        as_unicode do
          text.split(NEWLINE).map do |line|
            modified_line = wrap_line line
            indent_line modified_line
          end * NEWLINE
        end
      end

      private

      # Calculate string length without color escapes
      #
      # @api private
      def actual_length(string) #, width)
        width + (string.length - TTY.terminal.color.remove(string).length)
      end

      # Wrap line at given width
      #
      # @param [String] line
      #
      # @param [Integer] width
      #
      # @return [String]
      #
      # @api private
      def wrap_line(line) #, width)
        length = actual_length line #, width
        line.strip.gsub(/\n/,' ').squeeze(' ').
          gsub(/(.{1,#{length}})(?:\s+|$\n?)|(.{1,#{length}})/, "\\1\\2\n").strip
      end

      # Indent string by given value
      #
      # @param [String] text
      #
      # @param [Integer] indent
      #
      # @return [String]
      #
      # @api private
      def indent_line(text) #, indent)
        text.split(NEWLINE).each do |line|
          line.insert(0, SPACE * indent)
        end
      end

    end # Wrapping
  end # Text
end # TTY<commit_msg>Clean up dead code.<commit_after># -*- encoding: utf-8 -*-

module TTY
  class Text

    # A class responsible for text wrapping operations
    class Wrapping
      include Unicode

      attr_reader :text

      attr_reader :width

      attr_reader :indent

      # Initialize a Wrapping
      #
      # @param [String] text
      #   the text to be wrapped
      #
      # @overload new(text, value)
      #   wraps text at given value
      #
      #   @param [Integer] value
      #
      # @overload new(text, value, options)
      #   @param [Integer] value
      #   @param [Hash] options
      #   @option options [Symbol] :indent the indentation
      #
      # @api private
      def initialize(text, *args)
        options = Utils.extract_options!(args)
        @text   = text
        @width  = options.fetch(:width) { DEFAULT_WIDTH }
        @indent = options.fetch(:indent) { 0 }
        @width  = args[0] unless args.empty?
      end

      # Wrap a text into lines no longer than width.
      #
      # @see TTY::Text#wrap
      #
      # @api private
      def wrap
        as_unicode do
          text.split(NEWLINE).map do |line|
            modified_line = wrap_line line
            indent_line modified_line
          end * NEWLINE
        end
      end

      private

      # Calculate string length without color escapes
      #
      # @param [String] string
      #
      # @api private
      def actual_length(string)
        width + (string.length - TTY.terminal.color.remove(string).length)
      end

      # Wrap line at given width
      #
      # @param [String] line
      #
      # @param [Integer] width
      #
      # @return [String]
      #
      # @api private
      def wrap_line(line)
        length = actual_length line
        line.strip.gsub(/\n/,' ').squeeze(' ').
          gsub(/(.{1,#{length}})(?:\s+|$\n?)|(.{1,#{length}})/, "\\1\\2\n").strip
      end

      # Indent string by given value
      #
      # @param [String] text
      #
      # @param [Integer] indent
      #
      # @return [String]
      #
      # @api private
      def indent_line(text)
        text.split(NEWLINE).each do |line|
          line.insert(0, SPACE * indent)
        end
      end

    end # Wrapping
  end # Text
end # TTY
{'fraction_non_alphanumeric': 0.11096345514950166, 'fraction_numerical': 0.0035437430786267998, 'mean_word_length': 1.6627358490566038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357421', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1361, 'n_words': 373}