Class: Identifier::Global::Wikidata

Inherits:
Identifier::Global show all
Defined in:
app/models/identifier/global/wikidata.rb

Overview

Constant Summary collapse

NAMESPACES =

This is not a comprehensive map of Namespaces, but rather ones envisioned of possibly being useful at some point, maybe.

As implemented we should be using 'Q' nearly everywhere, but perhaps also 'P'

%w{Q P}.freeze
URI_BASE =
'http://www.wikidata.org/wiki/'.freeze

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from Identifier::Global

#relation

Instance Method Summary collapse

Methods inherited from Identifier::Global

#build_cached, #dwc_occurrences, #is_global?, #sv_resolves?

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Instance Method Details

#data_existsObject (private)



43
44
45
46
47
48
49
50
# File 'app/models/identifier/global/wikidata.rb', line 43

def data_exists
  return if errors.any?
  # wikidata-client doesn't use prepended 'Prefix:' in query
  a = ::Wikidata::Item.find(identifier)
  if a.nil?
    errors.add(:identifier, "Can not find #{identifier} in wikidata.")
  end
end

#namespace_formatObject (private)



39
40
41
# File 'app/models/identifier/global/wikidata.rb', line 39

def namespace_format
  errors.add(:identifier, 'Identifier is not prefixed with an recognized "namespace".') unless identifier =~ /\A#{NAMESPACES.join('|')}\d+/
end

#namespace_stringObject



19
20
21
22
# File 'app/models/identifier/global/wikidata.rb', line 19

def namespace_string
  identifier =~ /\A(\D+)\d+/
  $1
end

#prefixed_identifierObject



28
29
30
31
32
33
34
35
# File 'app/models/identifier/global/wikidata.rb', line 28

def prefixed_identifier
  case namespace_string
  when 'P'
    'Property:' + identifier
  else
    identifier
  end
end

#uriObject



24
25
26
# File 'app/models/identifier/global/wikidata.rb', line 24

def uri
  URI_BASE + prefixed_identifier
end