Skip to content

Instantly share code, notes, and snippets.

@AshKyd
Last active August 29, 2015 14:04
Show Gist options
  • Save AshKyd/12fe92d66e674aceffc1 to your computer and use it in GitHub Desktop.
Save AshKyd/12fe92d66e674aceffc1 to your computer and use it in GitHub Desktop.
Compile a dataset from the "LGBT rights by country or territory" wikipedia page. https://en.wikipedia.org/wiki/LGBT_rights_by_country_or_territory
var dataset = [];
/**
* Get an overall yes or no value for the cell. A no trumps a yes.
*/
function imgVal(cell){
var val;
$('img',cell).each(function(){
var alt = $(this).attr('alt');
if(alt === 'No'){
val = 'no';
} else if(alt === 'Yes' && !val) {
val = 'yes';
}
});
return val || 'unknown';
}
$('th:contains("LGBT rights in")').closest('table').each(function(){
$('tr:not([bgcolor])',this).each(function(i,row){
var country = $.trim($('td:eq(0)',row).text().match(/([^(]+)/)[0]);
var legal = imgVal($('td:eq(1)',row));
var marriage = (function(){
if(imgVal($('td:eq(3)',row)) === 'yes'){ return 'yes' }
if(imgVal($('td:eq(2)',row)) === 'yes'){ return 'recognised' }
return 'no';
})();
dataset.push({country:country,legal:legal,marriage:marriage});
});
});
console.log(JSON.stringify(dataset));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment