<commit_before>require "jiffy_enum"

module JiffyEnums
  include Enumerable
  # ordinals start from index 1 and NOT 0
  def define(key, value = nil, &overrides)
    @size = (@size || 0) + 1
    @hash ||= {}
    the_enum = self.new(key, value, @size )
    @hash[key] = the_enum
    @hash[key.to_s] =the_enum
    define_singleton_method(key) do
      the_enum
    end
    the_enum.instance_eval(&overrides) unless overrides.nil?
  end

  def [] (key)
    @hash[key]
  end


  def each
    @hash.each do |key, value|
      yield key, value
    end
  end

  def all
    @hash.values
  end

  def for_value (value)
    all.select do |enum|
      enum.value == value
    end.first
  end

  def for_ordinal (ordinal)
    all.select do |enum|
      enum.ordinal == ordinal
    end.first
  end

  def all_to_hash
    hash = {}
    each do |key, value|
      hash[key] = value.value
    end
    hash
  end

  def to_coffee(baseHashStr)
    final_coffee = ""
    final_variable = self.name.split("::").inject(baseHashStr) do |result,part|
      final_coffee += "#{result}.#{part} ||= {}\n"
      "#{result}.#{part}"
    end

    final_coffee = final_coffee + "#{final_variable} = new JiffyEnums #{
      @hash.map do |key, enum|
        "#{key}:new JiffyEnum(\"#{enum.key}\", \"#{enum.value}\", #{enum.ordinal})"
      end.join(", ")
    }\n"
    final_coffee
  end
end<commit_msg>fixing generating coffee script<commit_after>require "jiffy_enum"

module JiffyEnums
  extend Enumerable
  # ordinals start from index 1 and NOT 0
  def define(key, value = nil, &overrides)
    @size = (@size || 0) + 1
    @hash ||= {}
    @array ||= []
    the_enum = self.new(key, value, @size )
    @hash[key]      = the_enum
    @hash[key.to_s] = the_enum
    @array << the_enum
    define_singleton_method(key) do
      the_enum
    end
    the_enum.instance_eval(&overrides) unless overrides.nil?
  end

  def [] (key)
    @hash[key]
  end


  def each
    @array.each do |value|
      yield value
    end
  end

  def all
    @array.map{|x|x}
  end

  def for_value (value)
    all.select do |enum|
      enum.value == value
    end.first
  end

  def for_ordinal (ordinal)
    @array[ordinal - 1]
  end

  def all_to_hash
    hash = {}
    each do | value|
      hash[value.key] = value.value
    end
    hash
  end

  def to_coffee(baseHashStr)
    final_coffee = ""
    final_variable = self.name.split("::").inject(baseHashStr) do |result,part|
      final_coffee += "#{result}.#{part} ||= {}\n"
      "#{result}.#{part}"
    end

    final_coffee = final_coffee + "#{final_variable} = new JiffyEnums #{
      @array.map do |enum|
        "#{enum.key}:new JiffyEnum(\"#{enum.key}\", \"#{enum.value}\", #{enum.ordinal})"
      end.join(", ")
    }\n"
    final_coffee
  end
end
{'fraction_non_alphanumeric': 0.142183532825535, 'fraction_numerical': 0.003264417845484222, 'mean_word_length': 2.531370038412292, 'pattern_counts': {'":': 2, '<': 5, '<?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': '66958', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1029, 'n_words': 239}