<commit_before>module Enumerize
  class Attribute
    attr_reader :name, :values, :default_value

    def initialize(klass, name, options={})
      raise ArgumentError, ':in option is required' unless options[:in]

      extend Multiple if options[:multiple]

      @klass  = klass
      @name   = name.to_sym
      @values = Array(options[:in]).map { |v| Value.new(self, *v) }
      @value_hash = Hash[@values.map { |v| [v.value.to_s, v] }]
      @value_hash.merge! Hash[@values.map { |v| [v.to_s, v] }]

      if options[:default]
        @default_value = find_default_value(options[:default])
        raise ArgumentError, 'invalid default value' unless @default_value
      end

      # Define methods to get each value
      @values.each do |v|
        metaclass = class << self; self; end
        metaclass.send(:define_method, v.to_s) { v.value }
      end
    end

    def find_default_value(value)
      if value.respond_to?(:call)
        value
      else
        find_value(value)
      end
    end

    def find_value(value)
      @value_hash[value.to_s] unless value.nil?
    end

    def value_for(value)
      find_value(value).value
    end

    def i18n_suffix
      @klass.model_name.i18n_key if @klass.respond_to?(:model_name)
    end

    def options(options = {})
      values = if options.empty?
        @values
      else
        raise ArgumentError, 'Options cannot have both :only and :except' if options[:only] && options[:except]
<commit_msg>Add 'name'_text shortcut method to get the text for a value, remove the value_for method because its a duplicate of existing .find_value(:name).value<commit_after>module Enumerize
  class Attribute
    attr_reader :name, :values, :default_value

    def initialize(klass, name, options={})
      raise ArgumentError, ':in option is required' unless options[:in]

      extend Multiple if options[:multiple]

      @klass  = klass
      @name   = name.to_sym
      @values = Array(options[:in]).map { |v| Value.new(self, *v) }
      @value_hash = Hash[@values.map { |v| [v.value.to_s, v] }]
      @value_hash.merge! Hash[@values.map { |v| [v.to_s, v] }]

      if options[:default]
        @default_value = find_default_value(options[:default])
        raise ArgumentError, 'invalid default value' unless @default_value
      end

      # Define methods to get each value
      @values.each do |v|
        metaclass = class << self; self; end
        metaclass.send(:define_method, v.to_s) { v.value }
        metaclass.send(:define_method, v.to_s + '_text' ) { v.text }
      end
    end

    def find_default_value(value)
      if value.respond_to?(:call)
        value
      else
        find_value(value)
      end
    end

    def find_value(value)
      @value_hash[value.to_s] unless value.nil?
    end

    def i18n_suffix
      @klass.model_name.i18n_key if @klass.respond_to?(:model_name)
    end

    def options(options = {})
      values = if options.empty?
        @values
      else
        raise ArgumentError, 'Options cannot have both :only and :except' if options[:only] && options[:except]

{'fraction_non_alphanumeric': 0.1108222294442639, 'fraction_numerical': 0.0025999350016249595, 'mean_word_length': 2.68622754491018, 'pattern_counts': {'":': 0, '<': 7, '<?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': '633432', 'n_tokens_mistral': 989, 'n_tokens_neox': 970, 'n_words': 259}