Class: Wikidata::Item

Inherits:
Entity
  • Object
show all
Defined in:
lib/wikidata/item.rb

Constant Summary collapse

DEFAULT_QUERIES =
{
  search: {
    action: 'query',
    list: 'search',
    sroffset: 0,
    srlimit: 10
  },
  find: {
    action: 'wbgetentities',
    sites: 'enwiki'
  }
}.freeze

Class Method Summary collapse

Methods inherited from Entity

entity_id, #id, #initialize, #inspect, #properties, #property, #property_id, #property_ids, #property_keys, #property_name, #title, #url

Constructor Details

This class inherits a constructor from Wikidata::Entity

Class Method Details

._find(finder = :ids, list = '', query = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/wikidata/item.rb', line 25

def _find finder = :ids, list = '', query = {}
  q = DEFAULT_QUERIES[:find]
        .merge( query )
        .merge( finder => Array(list).join('|') )
  Wikidata::Client.new( q ).response.tap do |resp|
    return resp.results.first unless list.is_a?(Array)
  end
end

.find(ids, query = {}) ⇒ Object



17
18
19
# File 'lib/wikidata/item.rb', line 17

def find ids, query = {}
  _find :ids, ids, query
end

.find_by_title(titles, query = {}) ⇒ Object



21
22
23
# File 'lib/wikidata/item.rb', line 21

def find_by_title titles, query = {}
  _find :titles, titles, query
end

.search(search, query = {}) ⇒ Object



34
35
36
37
# File 'lib/wikidata/item.rb', line 34

def search search, query = {}
  q = DEFAULT_QUERIES[:search].merge( srsearch: search ).merge(query)
  Wikidata::Client.new( q ).response
end