<commit_before># encoding: utf-8

$LOAD_PATH.unshift File.expand_path(
  File.join(File.dirname(__FILE__), '../lib'))

module CapeCod

  require 'cape-cod/version'

  ESCAPE_CODES = {
    reset:          0,
    bold:           1,
    dark:           2,
    italic:         3,
    underline:      4,
    blink:          5,
    rapid_blink:    6,
    negative:       7,
    concealed:      8,
    strikethrough:  9,

    # Foreground color
    black:         30,
    red:           31,
    green:         32,
    yellow:        33,
    blue:          34,
    magenta:       35,
    cyan:          36,
    white:         37,

    # Background color
    on_black:      40,
    on_red:        41,
    on_green:      42,
    on_yellow:     43,
    on_blue:       44,
    on_magenta:    45,
    on_cyan:       46,
    on_white:      47,
  }.freeze

  #
  # Define helper methods for applying the escape codes
  #
  ESCAPE_CODES.each do |code, _|
    define_method code do
      CapeCod.apply_escape_sequence(code, self)
    end

    define_singleton_method code do |string|
       CapeCod.apply_escape_sequence(code, string)
    end
  end

  private

  #
  # Returns the ANSI escape sequence for a given escape code.
  #
  def self.escape_sequence_for(code)
    "\e[#{ESCAPE_CODES.fetch(code)}m"
  end

  #<commit_msg>Add support for passing a block to CapeCod methods<commit_after># encoding: utf-8

$LOAD_PATH.unshift File.expand_path(
  File.join(File.dirname(__FILE__), '../lib'))

module CapeCod

  require 'cape-cod/version'

  ESCAPE_CODES = {
    reset:          0,
    bold:           1,
    dark:           2,
    italic:         3,
    underline:      4,
    blink:          5,
    rapid_blink:    6,
    negative:       7,
    concealed:      8,
    strikethrough:  9,

    # Foreground color
    black:         30,
    red:           31,
    green:         32,
    yellow:        33,
    blue:          34,
    magenta:       35,
    cyan:          36,
    white:         37,

    # Background color
    on_black:      40,
    on_red:        41,
    on_green:      42,
    on_yellow:     43,
    on_blue:       44,
    on_magenta:    45,
    on_cyan:       46,
    on_white:      47,
    }.freeze

  #
  # Define helper methods for applying the escape codes
  #
  ESCAPE_CODES.each do |code, _|
    define_method code do
      CapeCod.apply_escape_sequence(code, self)
    end

    define_singleton_method code do |obj = '', &block|
      obj = obj.to_s
      return CapeCod.escape_sequence_for(code) if obj.empty? unless block

      obj += block.call if block

      CapeCod.apply_escape_sequence(code, obj)
    end
  end

  private

  #
  # Returns the ANSI escape sequence for a given escape +code+.
  #
  def self.escape_sequence_for(code)
    "\e[#{ESCAPE_CODES.fetch(code)}m"
  end

  #
{'fraction_non_alphanumeric': 0.0918185066095034, 'fraction_numerical': 0.030725259021078956, 'mean_word_length': 1.6743075453677172, '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': '2433269', 'n_tokens_mistral': 1027, 'n_tokens_neox': 985, 'n_words': 239}