<commit_before>module Sickill
  module Rainbow
  
    # I retrieve ANSI color code from a color name, an html color code
    # or an RGB color
    class ANSIColorCode
    
      # +ground+ is one of :foreground, :background
      def initialize ground, *color
        @ground = ground
        if color.size == 1
          @color = color.first
        else
          @color = color
        end
      end
      
      # Get the ANSI color code.
      def code
        case @color
          when Symbol then code_from_name
          when String then code_from_html
          when Array then code_from_rgb
        end
      end
      
      private
      
      def code_from_name
        validate_color_name
        TERM_COLORS[@color] + (@ground == :foreground ? 30 : 40)
      end
      
      def code_from_html
        @color = @color.gsub("#", "")
        red, green, blue = @color[0..1].to_i(16), @color[2..3].to_i(16), @color[4..5].to_i(16)
        get_rgb_code(red, green, blue)
      end
      
      def code_from_rgb
        unless @color.size == 3
          raise ArgumentError.new("Bad number of arguments for RGB color definition, should be 3") 
        end
        get_rgb_code(@color[0], @color[1], @color[2])
      end
      
      def validate_color_name
        color_names = TERM_COLORS.keys
        unless color_names.include?(@color)<commit_msg>improve readability for getting rgb from html<commit_after>module Sickill
  module Rainbow
  
    # I retrieve ANSI color code from a color name, an html color code
    # or an RGB color
    class ANSIColorCode
    
      # +ground+ is one of :foreground, :background
      def initialize ground, *color
        @ground = ground
        if color.size == 1
          @color = color.first
        else
          @color = color
        end
      end
      
      # Get the ANSI color code.
      def code
        case @color
          when Symbol then code_from_name
          when String then code_from_html
          when Array then code_from_rgb
        end
      end
      
      private
      
      def code_from_name
        validate_color_name
        TERM_COLORS[@color] + (@ground == :foreground ? 30 : 40)
      end
      
      def code_from_html
        @color = @color.gsub("#", "")
        red, green, blue = rgb_from_html
        get_rgb_code(red, green, blue)
      end
      
      def rgb_from_html
        red = @color[0..1].to_i(16)
        green = @color[2..3].to_i(16)
        blue = @color[4..5].to_i(16)
        [red, green, blue]
      end
      
      def code_from_rgb
        unless @color.size == 3
          raise ArgumentError.new("Bad number of arguments for RGB color definition, should be 3") 
        end
        get_rgb_code(@color[0], @color[1], @color[2])
      end
      
      def validate_color_name
        color_names = TERM_COLORS.keys
        unless color_names.include?(@color)
{'fraction_non_alphanumeric': 0.0807625649913345, 'fraction_numerical': 0.015251299826689775, 'mean_word_length': 1.7459562321598479, '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': '4855203', 'n_tokens_mistral': 896, 'n_tokens_neox': 859, 'n_words': 255}