<commit_before>module Alf
  module Text

    #
    # Implements Alf::Renderer for outputting beautiful text tables.
    #
    class Renderer < ::Alf::Renderer
  
      module Utils
  
        def looks_a_relation?(value)
          value.is_a?(Alf::Iterator) or
            (value.is_a?(Array) && !value.empty? && value.all?{|v| v.is_a?(Hash)})
        end
  
        def max(x, y)
          return y if x.nil?
          return x if y.nil?
          x > y ? x : y
        end
  
      end
      include Utils
  
      class Cell
        include Utils
  
        def initialize(value)
          @value = value
        end
  
        def min_width
          @min_width ||= rendering_lines.inject(0) do |maxl,line|
            max(maxl,line.size)
          end
        end
  
        def rendering_lines(size = nil)
          if size.nil?
            text_rendering.split(/\n/)
          elsif @value.is_a?(Numeric)
            rendering_lines(nil).collect{|l| "%#{size}s" % l}
          else
            rendering_lines(nil).collect{|l| "%-#{size}s" % l}
          end
        end
  
        def text_rendering
          @text_rendering ||= case (value = @value)
            when NilClass
              "[nil]"
            when Symbol
              value.inspect
            when Float
              "%.7f" % value
            when Hash
              value.inspect<commit_msg>Use %.3f for floats by default<commit_after>module Alf
  module Text

    #
    # Implements Alf::Renderer for outputting beautiful text tables.
    #
    class Renderer < ::Alf::Renderer
  
      module Utils
  
        def looks_a_relation?(value)
          value.is_a?(Alf::Iterator) or
            (value.is_a?(Array) && !value.empty? && value.all?{|v| v.is_a?(Hash)})
        end
  
        def max(x, y)
          return y if x.nil?
          return x if y.nil?
          x > y ? x : y
        end
  
      end
      include Utils
  
      class Cell
        include Utils
  
        def initialize(value)
          @value = value
        end
  
        def min_width
          @min_width ||= rendering_lines.inject(0) do |maxl,line|
            max(maxl,line.size)
          end
        end
  
        def rendering_lines(size = nil)
          if size.nil?
            text_rendering.split(/\n/)
          elsif @value.is_a?(Numeric)
            rendering_lines(nil).collect{|l| "%#{size}s" % l}
          else
            rendering_lines(nil).collect{|l| "%-#{size}s" % l}
          end
        end
  
        def text_rendering
          @text_rendering ||= case (value = @value)
            when NilClass
              "[nil]"
            when Symbol
              value.inspect
            when Float
              "%.3f" % value
            when Hash
              value.inspect
{'fraction_non_alphanumeric': 0.10061527325370974, 'fraction_numerical': 0.0018096272167933405, 'mean_word_length': 1.344359626802375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6853451', 'n_tokens_mistral': 843, 'n_tokens_neox': 849, 'n_words': 200}