Class: Wikimelon::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/wikimelon/reference.rb

Overview

A citation attached to a Statement. Holds a bag of snaks keyed by property, commonly P248 (“stated in”), P854 (“reference URL”), P813 (“retrieved”), P1476 (“title”), P143 (“imported from”).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Reference

Returns a new instance of Reference.



10
11
12
# File 'lib/wikimelon/reference.rb', line 10

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/wikimelon/reference.rb', line 8

def raw
  @raw
end

Instance Method Details

#propertiesObject



18
19
20
# File 'lib/wikimelon/reference.rb', line 18

def properties
  @raw['snaks-order'] || (@raw['snaks'] || {}).keys
end

#snaks(property_id) ⇒ Object



14
15
16
# File 'lib/wikimelon/reference.rb', line 14

def snaks(property_id)
  (@raw.dig('snaks', property_id) || []).map { |s| Statement.new('mainsnak' => s) }
end