Commit 00d00ed6 authored by Smari McCarthy's avatar Smari McCarthy
Browse files

Show results

parent ce8e64e4
......@@ -45,8 +45,10 @@ Marka.prototype.doConversions = function() {
$(".marka").each(function(index, value) {
var text = $(value).text();
var res = self.splitSymbols(text);
if (!res) {
if (res === false) {
$(value).replaceWith(text)
} else {
$(value).text($(value).text() + " -> " + res.number + " " + res.symbol + (res.certain?"":" (not sure)"));
}
});
}
......@@ -58,41 +60,59 @@ Marka.prototype.splitSymbols = function(text) {
} catch (e) {
return false;
}
var residual = text.replace(numbers, "");
number = number.replace(",", "")
realnumber = parseFloat(number);
if (!realnumber) { return false; }
var residual = text.replace(numbers, "")
var result = this.findSymbol(residual);
return true;
if (result.symbol == null) {
return false;
}
result.number = realnumber;
return result;
}
Marka.prototype.findSymbol = function(text) {
var result = {certain: false, symbol: null}
text = $.trim(text);
console.log(">"+text+"<");
if (text.match(/[A-Z]{3}/)) {
for (code in currency_info) {
if (code == text) {
console.log("FOUND SYMBOL: " + code);
result.symbol = code;
result.certain = true;
return result;
}
}
} else if (text.match(/[$€¥]/)) {
for (code in currency_info) {
if (currency_info[code].symbol == text) {
console.log("FOUND SYMBOL: " + code);
result.symbol = code;
result.certain = false;
if (text == "") {
result.certain = true;
}
return result;
}
}
} else {
for (code in currency_info) {
var name_plural = currency_info[code].name_plural.toLowerCase();
if (name_plural == text.toLowerCase()) {
result.symbol = code;
result.certain = true;
return result;
}
}
for (name in awkward_names) {
if (name == text.toLowerCase()) {
result.symbol = awkward_names[name];
result.certain = false;
return result;
}
}
}
return text;
/*
"ILS": {
"symbol": "₪",
"name": "Israeli New Sheqel",
"symbol_native": "₪",
"decimal_digits": 2,
"rounding": 0,
"code": "ILS",
"name_plural": "Israeli new sheqels"
},
*/
return result;
}
Marka.prototype.wrapNode = function() {
......@@ -177,6 +197,15 @@ Marka.prototype.setCookie = function (cname, cvalue, exdays) {
}
var awkward_names = {
"dollar": "USD",
"dollars": "USD",
"euro": "EUR",
"euros": "EUR",
"krone": "NOK",
"kronor": "SEK"
}
var currencies_available = [{
"resource": {
"classname": "Quote",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment