Class: Wikidata::Snak

Inherits:
HashedObject show all
Defined in:
lib/wikidata/snak.rb

Instance Attribute Summary

Attributes inherited from HashedObject

#data_hash

Instance Method Summary collapse

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

#inspectObject



32
33
34
# File 'lib/wikidata/snak.rb', line 32

def inspect
  "<#{self.class.to_s} type=#{snaktype} property_id=#{property_id}>"
end

#propertyObject



8
9
10
# File 'lib/wikidata/snak.rb', line 8

def property
  @property ||= Wikidata::Property.find_by_id(property_id)
end

#property_idObject



4
5
6
# File 'lib/wikidata/snak.rb', line 4

def property_id
  data_hash.property
end

#valueObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wikidata/snak.rb', line 12

def value
  @value ||= begin
    if datavalue['type'] == "wikibase-entityid"
      Wikidata::DataValues::Entity.new(datavalue.value)
    elsif datavalue['type'] == "time"
      Wikidata::DataValues::Time.new(datavalue.value)
    elsif datavalue['type'] == "globecoordinate"
      Wikidata::DataValues::Globecoordinate.new(datavalue.value)
    elsif datavalue['type'] == 'string'
      if property_id == "P18" || (@property && @property.datatype == "commonsMedia")
        Wikidata::DataValues::CommonsMedia.new({imagename: datavalue.value})
      else
        Wikidata::DataValues::String.new({string: datavalue.value})
      end
    else
      datavalue
    end
  end
end