Модуль:Wikidata/count

З Вікіпедыі, свабоднай энцыклапедыі

Дакументацыю да гэтага модуля можна стварыць у Модуль:Wikidata/count/Дакументацыя

local p = {}

function p.getCount( context, options )
	if ( not context ) then error( 'context not specified' ); end;
	if ( not options ) then error( 'options not specified' ); end;
	if ( not options.entity ) then error( 'options.entity missing' ); end;

	local claims;
	if options.property then -- TODO: Чаму тут можа не быць property?
		claims = context.selectClaims( options, options.property );
	end
	if claims == nil then
		return ''; --TODO error?
	end
	
	return table.getn(claims);
end

function p.isMultiple( context, options )
	local count = p.getCount( context, options );
	local multiple = '';
	if( count ~= nil and count ~= '' and count > 1 ) then
		multiple = 1;
	end
	return multiple;
end

return p