<commit_before>module Formtastic
  module Inputs
    module Base
      module Collections

        def label_method
          label_and_value_method(raw_collection).first
        end

        def value_method
          label_and_value_method(raw_collection).last
        end

        def label_and_value_method(_collection, grouped=false)
          sample = _collection.first || _collection.last

          case sample
          when Array
            label, value = :first, :last
          when Integer
            label, value = :to_s, :to_i
          when String, NilClass
            label, value = :to_s, :to_s
          end

          # Order of preference: user supplied method, class defaults, auto-detect
          label = (grouped ? options[:grouped_label_method] : options[:member_label]) || label || builder.collection_label_methods.find { |m| sample.respond_to?(m) }
          value = (grouped ? options[:grouped_value_method] : options[:member_value]) || value || builder.collection_value_methods.find { |m| sample.respond_to?(m) }

          [label, value]
        end<commit_msg>Ruby 1.8.7 Symbol happiness<commit_after>module Formtastic
  module Inputs
    module Base
      module Collections

        def label_method
          label_and_value_method(raw_collection).first
        end

        def value_method
          label_and_value_method(raw_collection).last
        end

        def label_and_value_method(_collection, grouped=false)
          sample = _collection.first || _collection.last

          case sample
          when Array
            label, value = :first, :last
          when Integer
            label, value = :to_s, :to_i
          when Symbol, String, NilClass
            label, value = :to_s, :to_s
          end

          # Order of preference: user supplied method, class defaults, auto-detect
          label = (grouped ? options[:grouped_label_method] : options[:member_label]) || label || builder.collection_label_methods.find { |m| sample.respond_to?(m) }
          value = (grouped ? options[:grouped_value_method] : options[:member_value]) || value || builder.collection_value_methods.find { |m| sample.respond_to?(m) }

          [label, value]
        end
{'fraction_non_alphanumeric': 0.08453887884267632, 'fraction_numerical': 0.00135623869801085, 'mean_word_length': 2.378625954198473, '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': '5095607', 'n_tokens_mistral': 611, 'n_tokens_neox': 595, 'n_words': 147}