<commit_before>module FacebookAdsApi
  ##
  #
  class GraphObjects
    ##
    #
    def initialize(path, client, params={})
      @path, @client = path, client
      resource_name = self.class.name.split('::')[-1]
      instance_name = resource_name.chop
  
      parent_module = self.class.to_s.split('::')[-2]
      full_module_path = parent_module == "FacebookAdsApi" ? (FacebookAdsApi) : (FacebookAdsApi.const_get parent_module)

      @instance_class = full_module_path.const_get instance_name
    end

    ##
    #
    def list(params={})
      raise "Can't list a Graph Object with out a client" unless @client
      response = @client.get @path, params
      resources = response["data"]

      resource_list = resources.map do |resource|
        @instance_class.new "#{@path.split('?').first}/#{resource['adgroup_id']}", @client, resource
      end

      resource_list
    end

    ##
    #
    def get(id)
      instance = @instance_class.new "#{@path}/#{id}", @client
    end

    ##
    #
    def inspect
      "<#{self.class} @path=#{@path}>"
    end
  end

  class GraphObject
    include Utils

    ##
    #
    def initialize(path, client, params={})
      @path, @client = path, client
      setup_properties params
    end

    ##
    #
    def inspect
      "<#{self.class} @path=#{@path}>"
    end

    protected

    ##
    #
    def resource(*resources)
      resources.each do |r|
        resource = resourceify r
        path = "#{@path}/#{resource.downcase}"
        enclosed_module = @sub_module == nil ? (FacebookAdsApi) : (FacebookAdsApi.const_get(@sub_module))
        resource_class = enclosed_module.const_get resource
        instance_variable_set("@#{r}", resource_class.new(path, @client))
      end

      self.class.instance_eval { attr_reader *resources }
    end

    ##
    #
    def setup_properties(hash)
      tmpclass = class << self; self; end

      hash.each do |key,val|
        tmpclass.send :define_method, key.to_sym, &lambda {val}
      end
    end
  end
end<commit_msg>Added to_hash method which loops through all the singleton methods that were created and creates a hash object.<commit_after>module FacebookAdsApi
  ##
  #
  class GraphObjects
    ##
    #
    def initialize(path, client, params={})
      @path, @client = path, client
      resource_name = self.class.name.split('::')[-1]
      instance_name = resource_name.chop
  
      parent_module = self.class.to_s.split('::')[-2]
      full_module_path = parent_module == "FacebookAdsApi" ? (FacebookAdsApi) : (FacebookAdsApi.const_get parent_module)

      @instance_class = full_module_path.const_get instance_name
    end

    ##
    #
    def list(params={})
      raise "Can't list a Graph Object with out a client" unless @client
      response = @client.get @path, params
      resources = response["data"]

      resource_list = resources.map do |resource|
        @instance_class.new "#{@path.split('?').first}/#{resource['adgroup_id']}", @client, resource
      end

      resource_list
    end

    ##
    #
    def get(id)
      instance = @instance_class.new "#{@path}/#{id}", @client
    end

    ##
    #
    def inspect
      "<#{self.class} @path=#{@path}>"
    end
  end

  class GraphObject
    include Utils

    ##
    #
    def initialize(path, client, params={})
      @path, @client = path, client
      setup_properties params
    end

    ##
    #
    def inspect
      "<#{self.class} @path=#{@path}>"
    end

    def to_hash
      hash = {}

      self.singleton_methods.each do |method|
        hash[method] = self.send method
      end

      hash
    end

    protected

    ##
    #
    def resource(*resources)
      resources.each do |r|
        resource = resourceify r
        path = "#{@path}/#{resource.downcase}"
        enclosed_module = @sub_module == nil ? (FacebookAdsApi) : (FacebookAdsApi.const_get(@sub_module))
        resource_class = enclosed_module.const_get resource
        instance_variable_set("@#{r}", resource_class.new(path, @client))
      end

      self.class.instance_eval { attr_reader *resources }
    end

    ##
    #
    def setup_properties(hash)
      tmpclass = class << self; self; end

      hash.each do |key,val|
        tmpclass.send :define_method, key.to_sym, &lambda {val}
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12581547064305684, 'fraction_numerical': 0.0009319664492078285, 'mean_word_length': 2.5130932896890346, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5270283', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1346, 'n_words': 304}