Class: Wikidata::DataValues::Entity

Inherits:
Value show all
Defined in:
lib/wikidata/datavalues/entity.rb

Instance Attribute Summary

Attributes inherited from HashedObject

#data_hash

Instance Method Summary collapse

Methods inherited from Value

#resolved

Methods inherited from HashedObject

#initialize, #method_missing

Constructor Details

This class inherits a constructor from Wikidata::HashedObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wikidata::HashedObject

Instance Method Details

#entityObject



17
18
19
20
21
22
23
# File 'lib/wikidata/datavalues/entity.rb', line 17

def entity
  if kind == 'item'
    @item ||= Wikidata::Item.find_by_id(item_id)
  else
    raise "Unknown entity type"
  end
end

#item_idObject



13
14
15
# File 'lib/wikidata/datavalues/entity.rb', line 13

def item_id
  "Q#{numeric_id}"
end

#kindObject



5
6
7
# File 'lib/wikidata/datavalues/entity.rb', line 5

def kind
  data_hash['entity-type']
end

#numeric_idObject



9
10
11
# File 'lib/wikidata/datavalues/entity.rb', line 9

def numeric_id
  data_hash['numeric-id']
end

#resolve!Object



25
26
27
# File 'lib/wikidata/datavalues/entity.rb', line 25

def resolve!
  entity
end

#to_sObject



29
30
31
32
33
34
35
# File 'lib/wikidata/datavalues/entity.rb', line 29

def to_s
  if @item.nil?
    item_id
  else
    "#{@item.label} (#{item_id})"
  end
end