<commit_before>module Boffin
  # A collection of utility methods that are used throughout the library
  module Utils

    # The number of seconds in an hour
    SECONDS_IN_HOUR  = 3600

    # Number of seconds in a day
    SECONDS_IN_DAY   = 24 * SECONDS_IN_HOUR

    # Number of seconds in a month
    SECONDS_IN_MONTH = 30 * SECONDS_IN_DAY

    # Number of seconds for a single value of each unit
    SECONDS_IN_UNIT  = {
      :hours  => SECONDS_IN_HOUR,
      :days   => SECONDS_IN_DAY,
      :months => SECONDS_IN_MONTH
    }

    module_function

    # @param [#to_s] thing
    #   A Module, Class, String, or anything in which the underscored value of
    #   `#to_s` is desirable.
    # @return [String]
    #   The underscored version of `#to_s` on thing
    # @note
    #   Originally pulled from ActiveSupport::Inflector
    def underscore(thing)
      thing.to_s.dup.tap do |word|
        word.gsub!(/::/, '_')
        word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!('-', '_')
        word.downcase!
      end
    end

    # @param [Object] obj any Ruby object
    # @return [true, false]
    #   `true` if the provided object is blank, examples of blank objects are:
    #   `[]`, `{}`, `nil`, `false`, `''`.
    def blank?(obj)
      obj.respond_to?(:empty?) ? obj.empty? : !obj
    end

    # @param [Object] obj any Ruby object
    # @return [true, false]
    #   `true` if the provided object responds to :id, other than it's
    #   internal object identifier
    #   `false` if the object does not respond to :id
    def respond_to_id?(obj)
      # NOTE: this feels like a hack. I'm sure there is a more elegant way
      # to determine whether the :id method is the built in Object#id but
      # I can't think of it
      obj.respond_to?(:id) and obj.id != obj.object_id
    end
<commit_msg>just check respond_to? :id if 1.9<commit_after>module Boffin
  # A collection of utility methods that are used throughout the library
  module Utils

    # The number of seconds in an hour
    SECONDS_IN_HOUR  = 3600

    # Number of seconds in a day
    SECONDS_IN_DAY   = 24 * SECONDS_IN_HOUR

    # Number of seconds in a month
    SECONDS_IN_MONTH = 30 * SECONDS_IN_DAY

    # Number of seconds for a single value of each unit
    SECONDS_IN_UNIT  = {
      :hours  => SECONDS_IN_HOUR,
      :days   => SECONDS_IN_DAY,
      :months => SECONDS_IN_MONTH
    }

    module_function

    # @param [#to_s] thing
    #   A Module, Class, String, or anything in which the underscored value of
    #   `#to_s` is desirable.
    # @return [String]
    #   The underscored version of `#to_s` on thing
    # @note
    #   Originally pulled from ActiveSupport::Inflector
    def underscore(thing)
      thing.to_s.dup.tap do |word|
        word.gsub!(/::/, '_')
        word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!('-', '_')
        word.downcase!
      end
    end

    # @param [Object] obj any Ruby object
    # @return [true, false]
    #   `true` if the provided object is blank, examples of blank objects are:
    #   `[]`, `{}`, `nil`, `false`, `''`.
    def blank?(obj)
      obj.respond_to?(:empty?) ? obj.empty? : !obj
    end

    # @param [Object] obj any Ruby object
    # @return [true, false]
    #   `true` if the provided object responds to :id, other than it's
    #   internal object identifier
    #   `false` if the object does not respond to :id
    def respond_to_id?(obj)
      # NOTE: this feels like a hack. I'm sure there is a more elegant way
      # to determine whether the :id method is the built in Object#id but
      # I can't think of it
      if RUBY_VERSION < "1.9"
        obj.respond_to?(:id) and obj.id != obj.object_id
      else
        obj.respond_to?(:id)
      end
    end

{'fraction_non_alphanumeric': 0.1186264308012487, 'fraction_numerical': 0.007284079084287201, 'mean_word_length': 2.396643109540636, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, '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': '2086930', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1311, 'n_words': 417}