<commit_before>require 'protobuf/enum_value'

module Protobuf
  class Enum

    def self.define(name, value)
      enum_value = ::Protobuf::EnumValue.new(self, name, value)
      const_set(name, enum_value)
      @values ||= {}
      @names ||= {}
      @values[name] = enum_value
      @names[value] = name
    end

    # Fetch the given enum by a variety of type-checking
    # mechanisms. This is useful for the enum field setters
    # as well as repeated enum field construction.
    def self.fetch(value)
      case value
      when ::Protobuf::EnumValue then
        value
      when Numeric then
        enum_by_value(value.to_i)
      when String, Symbol then
        value_by_name(value.to_sym)
      else
        nil
      end
    end

    def self.enum_by_value(value)
      value_by_name(name_by_value(value))
    end

    def self.name_by_value(value)
      value.nil? ? nil : @names[value]<commit_msg>check to_i when mapping name_by_value<commit_after>require 'protobuf/enum_value'

module Protobuf
  class Enum

    def self.define(name, value)
      enum_value = ::Protobuf::EnumValue.new(self, name, value)
      const_set(name, enum_value)
      @values ||= {}
      @names ||= {}
      @values[name] = enum_value
      @names[value] = name
    end

    # Fetch the given enum by a variety of type-checking
    # mechanisms. This is useful for the enum field setters
    # as well as repeated enum field construction.
    def self.fetch(value)
      case value
      when ::Protobuf::EnumValue then
        value
      when Numeric then
        enum_by_value(value.to_i)
      when String, Symbol then
        value_by_name(value.to_sym)
      else
        nil
      end
    end

    def self.enum_by_value(value)
      value_by_name(name_by_value(value))
    end

    def self.name_by_value(value)
      (!value.nil? && value.respond_to?(:to_i)) ? @names[value.to_i] : nil
{'fraction_non_alphanumeric': 0.09038054968287526, 'fraction_numerical': 0.0, 'mean_word_length': 2.5383177570093456, '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': '4113825', 'n_tokens_mistral': 607, 'n_tokens_neox': 594, 'n_words': 158}