with opal
(function($opal) {
var self = $opal.top, $scope = $opal, nil = $opal.nil, $breaker = $opal.breaker, $slice = $opal.slice, $hash2 = $opal.hash2;
$opal.add_stubs(['$send', '$&', '$collect', '$[]', '$keys', '$empty?', '$each', '$compact', '$flatten', '$==', '$first']);
return ($opal.Object._proto.$preferred_code = function(preferred_code_sets, codes_attribute, value_set_map) {try {
var $a, $b, TMP_1, $c, TMP_2, self = this, codes_value = nil, matching_code_sets = nil, code_set = nil;
if (codes_attribute == null) {
codes_attribute = "codes"
}
if (value_set_map == null) {
value_set_map = nil
}
codes_value = self.$send(codes_attribute);
preferred_code_sets = (function() {if (value_set_map !== false && value_set_map !== nil) {
return (preferred_code_sets['$&'](($a = ($b = value_set_map).$collect, $a._p = (TMP_1 = function(cs){var self = TMP_1._s || this;if (cs == null) cs = nil;
return cs['$[]']("set")}, TMP_1._s = self, TMP_1), $a).call($b)))
} else {
return preferred_code_sets
}; return nil; })();
matching_code_sets = preferred_code_sets['$&'](codes_value.$keys());
if (($a = matching_code_sets['$empty?']()) !== false && $a !== nil) {
return nil
} else if (value_set_map !== false && value_set_map !== nil) {
return ($a = ($c = matching_code_sets).$each, $a._p = (TMP_2 = function(matching_code_set){var self = TMP_2._s || this, $a, $b, TMP_3, $c, matching_codes = nil;if (matching_code_set == null) matching_code_set = nil;
matching_codes = codes_value['$[]'](matching_code_set)['$&'](($a = ($b = value_set_map).$collect, $a._p = (TMP_3 = function(cs){var self = TMP_3._s || this;if (cs == null) cs = nil;
if (cs['$[]']("set")['$=='](matching_code_set)) {
return cs['$[]']("values")
} else {
return []
}}, TMP_3._s = self, TMP_3), $a).call($b).$flatten().$compact());
if (($a = ($c = matching_codes['$empty?'](), ($c === nil || $c === false))) !== false && $a !== nil) {
$opal.$return($hash2(["code", "code_set"], {"code": matching_codes.$first(), "code_set": matching_code_set}))
} else {
return nil
};}, TMP_2._s = self, TMP_2), $a).call($c)
} else {
code_set = matching_code_sets.$first();
return $hash2(["code", "code_set"], {"code": codes_value['$[]'](code_set).$first(), "code_set": code_set});
};
} catch ($returner) { if ($returner === $opal.returner) { return $returner.$v } throw $returner; }
}, nil)
})(Opal);