<commit_before>//
//  SWXMLSelectMapping.swift
//  SWXMLMapping
//
//  Created by <NAME> on 12/02/16.
//
//

import Foundation

@objc(SWXMLSelection)
public protocol SWXMLSelection {
	init(attributes: [String : String]!)

	func mapObject(object: AnyObject!, withKeyPath keyPath: String!) -> AnyObject!
}

/*
	This mapping allows you to make a selection by instantiating a class which manages the query against a object/keyPath relationship. The result is essentially a collection of items.
	
	<select keyPath="property">
*/
@objc(SWXMLSelectMapping)
public class SWXMLSelectMapping: SWXMLMemberMapping {
	let mappingClass: SWXMLSelection.Type

	override init!(tag: String!, keyPath: String!, attributes: [String : String]!) {
		mappingClass = NSClassFromString(attributes["class"]!) as! SWXMLSelection.Type

		super.init(tag: tag, keyPath: keyPath, attributes: attributes)
	}

	override public func serializedObjectMember(object: AnyObject!, withMapping mapping: SWXMLMapping!) -> String! {
		let mappingObject = mappingClass.init(attributes: self.attributes)

		let mappedObject = mappingObject.mapObject(object, withKeyPath: self.keyPath)

		return SWXMLTags.tagNamed(self.tag, forValue: mapping.serializeObject(mappedObject))
	}
}<commit_msg>Allow mapping to be passed in, for access to e.g. metadata<commit_after>//
//  SWXMLSelectMapping.swift
//  SWXMLMapping
//
//  Created by <NAME> on 12/02/16.
//
//

import Foundation

@objc(SWXMLSelection)
public protocol SWXMLSelection {
	init(attributes: [String : String]!, mapping: SWXMLMapping)

	func mapObject(object: AnyObject!, withKeyPath keyPath: String!) -> AnyObject!
}

/*
	This mapping allows you to make a selection by instantiating a class which manages the query against a object/keyPath relationship. The result is essentially a collection of items.
	
	<select keyPath="property">
*/
@objc(SWXMLSelectMapping)
public class SWXMLSelectMapping: SWXMLMemberMapping {
	let mappingClass: SWXMLSelection.Type

	override init!(tag: String!, keyPath: String!, attributes: [String : String]!) {
		mappingClass = NSClassFromString(attributes["class"]!) as! SWXMLSelection.Type

		super.init(tag: tag, keyPath: keyPath, attributes: attributes)
	}

	override public func serializedObjectMember(object: AnyObject!, withMapping mapping: SWXMLMapping!) -> String! {
		let mappingObject = mappingClass.init(attributes: self.attributes, mapping: mapping)

		let mappedObject = mappingObject.mapObject(object, withKeyPath: self.keyPath)

		return SWXMLTags.tagNamed(self.tag, forValue: mapping.serializeObject(mappedObject))
	}
}
{'fraction_non_alphanumeric': 0.10597826086956522, 'fraction_numerical': 0.004658385093167702, 'mean_word_length': 5.4264339152119705, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '204122', 'n_tokens_mistral': 778, 'n_tokens_neox': 725, 'n_words': 218}