def truncate_array(string_array, limit = nil, separator = '', natural_separator = ' ')
      return string_array if limit.nil? || limit <= 0

      length = 0
      result = []

      string_array.each do |string|
        limit_left = calculate_limit_left(limit, length, result, separator)

        if string.length > limit_left
          result << truncate(string, limit_left, natural_separator)
          break
        end

        length += (result.any? ? separator.length : 0) + string.length
        result << string

        # No more strings will fit
        break if length + separator.length >= limit
      end

      result
    end
def truncate_array(string_array, limit = nil, separator = '', natural_separator = ' ')
      return string_array if limit.nil? || limit <= 0

      length = 0
      result = []

      string_array.each do |string|
        limit_left = calculate_limit_left(limit, length, result, separator)

        if string.length > limit_left
          result << truncate(string, limit_left, natural_separator)
          break
        end

        length += (result.any? ? separator.length : 0) + string.length
        result << string

        # No more strings will fit
        break if length + separator.length >= limit
      end

      result
    end
Truncates a string to a specific limit.

 @param [Array<String>] string_array input strings.
 @param [Integer,nil] limit characters number to truncate to.
 @param [String] separator separator that will be used to join array later.
 @param [String] natural_separator natural separator to truncate at.
 @return [String] truncated string.