Модуль:Wikidata/count

Материал из Frog Archive, свободного справочника
Перейти к навигации Перейти к поиску

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

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