Class: WikibaseRepresentable::Model::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/wikibase_representable/model/item.rb

Overview

Represents a single Wikibase item. See www.mediawiki.org/wiki/Wikibase/DataModel#Items

Constant Summary collapse

ENTITY_TYPE =
'item'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Item

Returns a new instance of Item.



18
19
20
21
22
23
24
25
26
# File 'lib/wikibase_representable/model/item.rb', line 18

def initialize(**kwargs)
  @type = ENTITY_TYPE
  @id = kwargs[:id]
  @labels_hash = kwargs[:labels_hash] || TermHash.new
  @descriptions_hash = kwargs[:descriptions_hash] || TermHash.new
  @alias_groups_hash = kwargs[:alias_groups_hash] || AliasGroupHash.new
  @site_links_hash = kwargs[:site_links_hash] || SiteLinkHash.new
  @statements_hash = kwargs[:statements_hash] || StatementHash.new
end

Instance Attribute Details

#alias_groups_hashObject

Returns the value of attribute alias_groups_hash.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def alias_groups_hash
  @alias_groups_hash
end

#descriptions_hashObject

Returns the value of attribute descriptions_hash.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def descriptions_hash
  @descriptions_hash
end

#idObject

Returns the value of attribute id.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def id
  @id
end

#labels_hashObject

Returns the value of attribute labels_hash.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def labels_hash
  @labels_hash
end

Returns the value of attribute site_links_hash.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def site_links_hash
  @site_links_hash
end

#statements_hashObject Also known as: claims_hash

Returns the value of attribute statements_hash.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def statements_hash
  @statements_hash
end

#typeObject

Returns the value of attribute type.



16
17
18
# File 'lib/wikibase_representable/model/item.rb', line 16

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/wikibase_representable/model/item.rb', line 56

def ==(other)
  other.class == self.class && other.state == state
end

#aliases_for_language(language_code) ⇒ Object



32
33
34
# File 'lib/wikibase_representable/model/item.rb', line 32

def aliases_for_language(language_code)
  alias_groups_hash.aliases_for_language(language_code)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/wikibase_representable/model/item.rb', line 60

def eql?(other)
  self == other
end

#label(language_code) ⇒ Object



28
29
30
# File 'lib/wikibase_representable/model/item.rb', line 28

def label(language_code)
  labels_hash.value_for_language(language_code)
end

Returns:

  • (Boolean)


48
49
50
# File 'lib/wikibase_representable/model/item.rb', line 48

def link_to_site?(site_id)
  site_links_hash.link_for_site?(site_id)
end


44
45
46
# File 'lib/wikibase_representable/model/item.rb', line 44

def site_link(site_id)
  site_links_hash.link_for_site(site_id)
end

#stateObject



52
53
54
# File 'lib/wikibase_representable/model/item.rb', line 52

def state
  [type, id, labels_hash, descriptions_hash, alias_groups_hash, site_links_hash, statements_hash]
end

#statements_by_property_id(property_id) ⇒ Object Also known as: claims_by_property_id



36
37
38
# File 'lib/wikibase_representable/model/item.rb', line 36

def statements_by_property_id(property_id)
  statements_hash.statements_by_property_id(property_id)
end

#statements_by_property_id?(property_id) ⇒ Boolean Also known as: claims_by_property_id?

Returns:

  • (Boolean)


40
41
42
# File 'lib/wikibase_representable/model/item.rb', line 40

def statements_by_property_id?(property_id)
  statements_hash.statements_by_property_id?(property_id)
end