<commit_before>'use strict';

// Utility functions for parsing dc-* directives (dc-multitext, etc)
//var util = require('../../bellows/pages/util');  // TODO: Remove if not used once page implemented

var dbeUtil = function() {
	var self = this; // For use inside nested anonymous functions where the value "this" can get lost
	this.dcMultitextToArray = function(elem) {
		// Return the multitext's values as [{wsid: 'en', value: 'word'}, {wsid: 'de', value: 'Wort'}]
		// NOTE: Returns a promise. Use .then() to access the actual data.
		var inputSystemDivs = elem.all(by.repeater('tag in config.inputSystems'));
		return inputSystemDivs.map(function(div) {
			var wsidSpan = div.$('.controls span.wsid');
			var wordElem = div.$('.controls input');
			return wsidSpan.getText().then(function(wsid) {
				return wordElem.getAttribute('value').then(function(word) {
					return {
						wsid: wsid,
						value: word,
					};
				});
			});
		});
	};
	this.dcMultitextToObject = function(elem) {
		// Return the multitext's values as [{en: 'word', de: 'Wort'}]
		// NOTE: Returns a promise. Use .then() to access the actual data.
		return self.dcMultitextToArray(elem).then(function(values) {
			var result = {};
			for (var i=0,l=values.length; i<l; i++) {
				result[values[i].wsid] = values[i].value;
			}
			return result;
		});
	};
	this.dcMultitextToValue = function(elem) {
		// Returns the value of the multitext's first writing system, no matter what writing system is first
		// NOTE: Returns a promise. Use .then() to access the actual data.
		return self.dcMultitextToArray(elem).then(function(values) {
			return values[0].value;
		});
	};
	
	this.dcOptionListToValue = function(elem) {
		var select = elem.$('.controls select');
		return select.$('option:checked').getText().then(function(text) {
			return text;
		});
	};
	
	this.dcMultiOptionListToValue = function(elem) {
		// At the moment these are identical to dc-optionlist directives.
		// When they change, this function will need to be rewritten
		return self.dcOptionListToValue(elem);
	};
	
	this.dcParsingFuncs = {
		'multitext': {
			'as_object': self.dcMultitextToObject,
			'as_value':  self.dcMultitextToValue,
			'as_array':  self.dcMultitextToArray,
			'default_strategy': 'as_object',
		},
		'optionlist': self.dcOptionListToValue,
		'multioptionlist': self.dcMultiOptionListToValue,
	};
	
	this.getParser = function(elem, multitext_strategy) {
		multitext_strategy = multitext_strategy || self.dcParsingFuncs.multitext.default_strategy;
		var switchDiv = elem.$('[data-on="config.fields[fieldName].type"] > div');
		return switchDiv.getAttribute('data-ng-switch-when').then(function(fieldType) {
			var parser;
			if (fieldType == 'multitext') {
				parser = self.dcParsingFuncs[fieldType][multitext_strategy];
			} else {
				parser = self.dcParsingFuncs[fieldType];
			}
			return parser;<commit_msg>Minor refactor to dbeUtil: rename parsing strategy<commit_after>'use strict';

// Utility functions for parsing dc-* directives (dc-multitext, etc)
//var util = require('../../bellows/pages/util');  // TODO: Remove if not used once page implemented

var dbeUtil = function() {
	var self = this; // For use inside nested anonymous functions where the value "this" can get lost
	this.dcMultitextToArray = function(elem) {
		// Return the multitext's values as [{wsid: 'en', value: 'word'}, {wsid: 'de', value: 'Wort'}]
		// NOTE: Returns a promise. Use .then() to access the actual data.
		var inputSystemDivs = elem.all(by.repeater('tag in config.inputSystems'));
		return inputSystemDivs.map(function(div) {
			var wsidSpan = div.$('.controls span.wsid');
			var wordElem = div.$('.controls input');
			return wsidSpan.getText().then(function(wsid) {
				return wordElem.getAttribute('value').then(function(word) {
					return {
						wsid: wsid,
						value: word,
					};
				});
			});
		});
	};
	this.dcMultitextToObject = function(elem) {
		// Return the multitext's values as [{en: 'word', de: 'Wort'}]
		// NOTE: Returns a promise. Use .then() to access the actual data.
		return self.dcMultitextToArray(elem).then(function(values) {
			var result = {};
			for (var i=0,l=values.length; i<l; i++) {
				result[values[i].wsid] = values[i].value;
			}
			return result;
		});
	};
	this.dcMultitextToValue = function(elem) {
		// Returns the value of the multitext's first writing system, no matter what writing system is first
		// NOTE: Returns a promise. Use .then() to access the actual data.
		return self.dcMultitextToArray(elem).then(function(values) {
			return values[0].value;
		});
	};
	
	this.dcOptionListToValue = function(elem) {
		var select = elem.$('.controls select');
		return select.$('option:checked').getText().then(function(text) {
			return text;
		});
	};
	
	this.dcMultiOptionListToValue = function(elem) {
		// At the moment these are identical to dc-optionlist directives.
		// When they change, this function will need to be rewritten
		return self.dcOptionListToValue(elem);
	};
	
	this.dcParsingFuncs = {
		'multitext': {
			'multitext_as_object': self.dcMultitextToObject,
			'multitext_as_value':  self.dcMultitextToValue,
			'multitext_as_array':  self.dcMultitextToArray,
			'default_strategy': 'multitext_as_object',
		},
		'optionlist': self.dcOptionListToValue,
		'multioptionlist': self.dcMultiOptionListToValue,
	};
	
	this.getParser = function(elem, multitext_strategy) {
		multitext_strategy = multitext_strategy || self.dcParsingFuncs.multitext.default_strategy;
		var switchDiv = elem.$('[data-on="config.fields[fieldName].type"] > div');
		return switchDiv.getAttribute('data-ng-switch-when').then(function(fieldType) {
			var parser;
			if (fieldType == 'multitext') {
				parser = self.dcParsingFuncs[fieldType][multitext_strategy];
			} else {
				parser = self.dcParsingFuncs[fieldType];
			}
			return parser;
{'fraction_non_alphanumeric': 0.14275944605915541, 'fraction_numerical': 0.0006838775859121217, 'mean_word_length': 4.047454702329595, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3734073', 'n_tokens_mistral': 2132, 'n_tokens_neox': 1910, 'n_words': 463}