Class: Wikidata::Entity
- Inherits:
-
Object
- Object
- Wikidata::Entity
- Extended by:
- Forwardable
- Defined in:
- lib/wikidata/entity.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Class Method Summary collapse
-
.entity_id(attribute) ⇒ Object
TODO Handle other types www.wikidata.org/wiki/Wikidata:Glossary#Entities.2C_items.2C_properties_and_queries.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(hash) ⇒ Entity
constructor
A new instance of Entity.
- #inspect ⇒ Object
- #properties(code) ⇒ Object
- #property(code) ⇒ Object
- #property_id(code) ⇒ Object
- #property_ids(code) ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(hash) ⇒ Entity
Returns a new instance of Entity.
8 9 10 11 |
# File 'lib/wikidata/entity.rb', line 8 def initialize hash @hash = Hashie::Mash.new hash @_properties = {} end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
5 6 7 |
# File 'lib/wikidata/entity.rb', line 5 def hash @hash end |
Class Method Details
.entity_id(attribute) ⇒ Object
TODO Handle other types www.wikidata.org/wiki/Wikidata:Glossary#Entities.2C_items.2C_properties_and_queries
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/wikidata/entity.rb', line 66 def entity_id attribute return unless attribute.mainsnak.datavalue attribute.mainsnak.datavalue.value.tap do |h| case h['entity-type'] when 'item' return "Q#{h['numeric-id']}" else return nil end end end |
Instance Method Details
#id ⇒ Object
13 14 15 16 |
# File 'lib/wikidata/entity.rb', line 13 def id return hash['id'] if hash['id'] return hash['title'] if hash['title'] end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/wikidata/entity.rb', line 58 def inspect "<#{self.class} id: #{id}, title: \"#{title}\">" end |
#properties(code) ⇒ Object
40 41 42 |
# File 'lib/wikidata/entity.rb', line 40 def properties code @_properties[code] ||= Array(raw_property(code)).map {|a| Wikidata::Property.build a } end |
#property(code) ⇒ Object
50 51 52 |
# File 'lib/wikidata/entity.rb', line 50 def property code properties(code).first end |
#property_id(code) ⇒ Object
54 55 56 |
# File 'lib/wikidata/entity.rb', line 54 def property_id code property_ids(code).first end |
#property_ids(code) ⇒ Object
44 45 46 47 48 |
# File 'lib/wikidata/entity.rb', line 44 def property_ids code Array(raw_property(code)).map do |attribute| self.class.entity_id attribute end.compact end |
#title ⇒ Object
18 19 20 21 22 |
# File 'lib/wikidata/entity.rb', line 18 def title return labels['en'].value if labels && labels['en'] return sitelinks['en'].value if sitelinks && sitelinks['en'] hash['title'] if hash['title'] end |