<commit_before>module Ultron
  class Entities
    include Enumerable

    def self.name_for_path
      self.name.split('::')[-1].downcase
    end

    def self.method_missing method_name, *args
      mname = method_name.to_s
      query = nil
      path  = self.name_for_path #if mname == 'get'
      path  = '%s/%s' % [path, args[0]] if mname == 'find'

      parts = mname.split /_and_/
      parts.each do |part|
        path  = self.send(:by_something, $1, args.shift) if part =~ /by_(.*)/
        query = self.send(:by_params, args[0]) if ['with', 'where'].include? part
      end

      response = Ultron::Connection.perform get_url path, query

      set = self.new response['data']['results']
      return set.first if set.count == 1
      set
    end

    def self.by_something something, id
      [something.pluralize, id, self.name_for_path].join '/'
    end

    def self.by_params params
      params.map { |k, v| '%s=%s&' % [k, v] }.join
    end

    def self.get_url path, query
      "%s%s?%s%s" % [Ultron::Config.instance.root_url, path, query, Ultron.auth(ENV['PRIVATE_KEY'], ENV['PUBLIC_KEY'])]
    end<commit_msg>case >>> if<commit_after>module Ultron
  class Entities
    include Enumerable

    def self.name_for_path
      self.name.split('::')[-1].downcase
    end

    def self.method_missing method_name, *args
      mname = method_name.to_s
      query = nil
      path  = self.name_for_path #if mname == 'get'
      path  = '%s/%s' % [path, args[0]] if mname == 'find'

      parts = mname.split /_and_/
      parts.each do |part|
        case part
          when /by_(.*)/
            path = self.send(:by_something, $1, args.shift)
          when 'with', 'where'
            query = self.send(:by_params, args[0])
        end
      end

      response = Ultron::Connection.perform get_url path, query
      set      = self.new response['data']['results']

      return set.first if set.count == 1
      set
    end

    def self.by_something something, id
    [something.pluralize, id, self.name_for_path].join '/'
    end

    def self.by_params params
      params.map { |k, v| '%s=%s&' % [k, v] }.join
    end

    def self.get_url path, query
      "%s%s?%s%s" % [Ultron::Config.instance.root_url, path, query, Ultron.auth(ENV['PRIVATE_KEY'], ENV['PUBLIC_KEY'])]
    end
{'fraction_non_alphanumeric': 0.1427951388888889, 'fraction_numerical': 0.004340277777777778, 'mean_word_length': 2.4300595238095237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1269331', 'n_tokens_mistral': 822, 'n_tokens_neox': 789, 'n_words': 193}