<commit_before>module AMEE
  module Profile
    class Profile < AMEE::Profile::Object

      def self.list(connection)
        # Load data from path
        response = connection.get('/profiles')
        # Parse data from response
        profiles = []
        if response.is_json?
          # Read JSON
          doc = JSON.parse(response)
          doc['profiles'].each do |p|
            data = {}
            data[:uid] = p['uid']
            data[:created] = DateTime.parse(p['created'])
            data[:modified] = DateTime.parse(p['modified'])
            data[:name] = p['name']
            data[:path] = "/#{p['path']}"
            # Create profile
            profile = Profile.new(data)
            # Store in array
            profiles << profile
          end
        else
          # Read XML
          doc = REXML::Document.new(response)
          REXML::XPath.each(doc, '/Resources/ProfilesResource/Profiles/Profile') do |p|
            data = {}
            data[:uid] = p.attributes['uid'].to_s
            data[:created] = DateTime.parse(p.attributes['created'].to_s)
            data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
            data[:name] = p.elements['Name'].text || data[:uid]
            data[:path] = "/#{p.elements['Path'].text || data[:uid]}"
            # Create profile
            profile = Profile.new(data)
            # Store connection in profile object
            profile.connection = connection
            # Store in array
            profiles << profile
          end
        end
        # Done
        return profiles
      rescue
        raise AMEE::BadData.new("Couldn't load Profile list.")
      end

      def self.create(connection)
        # Create new profile
        response = connection.post('/profiles', :profile => true)
        # Parse data from response
        if response.is_json?
          # Read JSON
          doc = JSON.parse(response)
          p = doc['profile']
          data = {}
          data[:uid] = p['uid']
          data[:created] = DateTime.parse(p['created'])
          data[:modified] = DateTime.parse(p['modified'])
          data[:name] = p['name']
          data[:path] = p['path']
          # Create profile
          profile = Profile.new(data)
          # Done
          return profile
        else
          # Read XML
          doc = REXML::Document.new(response)
          p = REXML::XPath.first(doc, '/Resources/ProfilesResource/Profile')
          data = {}
          data[:uid] = p.attributes['uid'].to_s
          data[:created] = DateTime.parse(p.attributes['created'].to_s)
          data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
          data[:name] = p.elements['Name'].text || data[:uid]
          data[:path] = p.elements['Path'].text || data[:uid]
          # Create profile
          profile = Profile.new(data)
          # Store connection in profile object
          profile.connection = connection
          # Done
          return profile
        end
      rescue
        raise AMEE::BadData.new("Couldn't create Profile.")
      end

  #    def delete
  #      # Create new profile
  #      response = connection.delete(full_path)
  #    end

    end
  end
end<commit_msg>Add Profile#delete<commit_after>module AMEE
  module Profile
    class Profile < AMEE::Profile::Object

      def self.list(connection)
        # Load data from path
        response = connection.get('/profiles')
        # Parse data from response
        profiles = []
        if response.is_json?
          # Read JSON
          doc = JSON.parse(response)
          doc['profiles'].each do |p|
            data = {}
            data[:uid] = p['uid']
            data[:created] = DateTime.parse(p['created'])
            data[:modified] = DateTime.parse(p['modified'])
            data[:name] = p['name']
            data[:path] = "/#{p['path']}"
            # Create profile
            profile = Profile.new(data)
            # Store in array
            profiles << profile
          end
        else
          # Read XML
          doc = REXML::Document.new(response)
          REXML::XPath.each(doc, '/Resources/ProfilesResource/Profiles/Profile') do |p|
            data = {}
            data[:uid] = p.attributes['uid'].to_s
            data[:created] = DateTime.parse(p.attributes['created'].to_s)
            data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
            data[:name] = p.elements['Name'].text || data[:uid]
            data[:path] = "/#{p.elements['Path'].text || data[:uid]}"
            # Create profile
            profile = Profile.new(data)
            # Store connection in profile object
            profile.connection = connection
            # Store in array
            profiles << profile
          end
        end
        # Done
        return profiles
      rescue
        raise AMEE::BadData.new("Couldn't load Profile list.")
      end

      def self.create(connection)
        # Create new profile
        response = connection.post('/profiles', :profile => true)
        # Parse data from response
        if response.is_json?
          # Read JSON
          doc = JSON.parse(response)
          p = doc['profile']
          data = {}
          data[:uid] = p['uid']
          data[:created] = DateTime.parse(p['created'])
          data[:modified] = DateTime.parse(p['modified'])
          data[:name] = p['name']
          data[:path] = p['path']
          # Create profile
          profile = Profile.new(data)
          # Done
          return profile
        else
          # Read XML
          doc = REXML::Document.new(response)
          p = REXML::XPath.first(doc, '/Resources/ProfilesResource/Profile')
          data = {}
          data[:uid] = p.attributes['uid'].to_s
          data[:created] = DateTime.parse(p.attributes['created'].to_s)
          data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
          data[:name] = p.elements['Name'].text || data[:uid]
          data[:path] = p.elements['Path'].text || data[:uid]
          # Create profile
          profile = Profile.new(data)
          # Store connection in profile object
          profile.connection = connection
          # Done
          return profile
        end
      rescue
        raise AMEE::BadData.new("Couldn't create Profile.")
      end

      def self.delete(connection, uid)
        # Delete profile
        connection.delete("/profiles/#{uid}")
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.12958662331630283, 'fraction_numerical': 0.0, 'mean_word_length': 1.7642276422764227, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1313401', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1710, 'n_words': 383}