Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/wikibase_representable/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
require 'wikibase_representable/model/snak_data_value_helper'
require 'wikibase_representable/model/statement_data_value_helper'

require 'wikibase_representable/model/alias_group_list'
require 'wikibase_representable/model/alias_group_hash'
require 'wikibase_representable/model/data_value'
require 'wikibase_representable/model/entity_id'
require 'wikibase_representable/model/entity_id_value'
require 'wikibase_representable/model/item'
require 'wikibase_representable/model/property'
require 'wikibase_representable/model/property_value_snak'
require 'wikibase_representable/model/site_link'
require 'wikibase_representable/model/site_link_list'
require 'wikibase_representable/model/snak_list'
require 'wikibase_representable/model/site_link_hash'
require 'wikibase_representable/model/snak_hash'
require 'wikibase_representable/model/statement'
require 'wikibase_representable/model/statement_list'
require 'wikibase_representable/model/statement_hash'
require 'wikibase_representable/model/term'
require 'wikibase_representable/model/term_list'
require 'wikibase_representable/model/term_hash'
require 'wikibase_representable/model/time_value'
require 'wikibase_representable/model/time'
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module WikibaseRepresentable
module Model
# Wraps a hash of Term arrays keyed by language code.
class AliasGroupList < Hash
# Hash of alias lists keyed by language code.
class AliasGroupHash < Hash
def aliases_for_language(language_code)
fetch(language_code, nil)
end
Expand Down
36 changes: 18 additions & 18 deletions lib/wikibase_representable/model/item.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'wikibase_representable/model/alias_group_list'
require 'wikibase_representable/model/site_link_list'
require 'wikibase_representable/model/statement_list'
require 'wikibase_representable/model/term_list'
require 'wikibase_representable/model/alias_group_hash'
require 'wikibase_representable/model/site_link_hash'
require 'wikibase_representable/model/statement_hash'
require 'wikibase_representable/model/term_hash'
require 'wikibase_representable/model/term'

module WikibaseRepresentable
Expand All @@ -13,44 +13,44 @@ module Model
class Item
ENTITY_TYPE = 'item'

attr_accessor :type, :id, :labels, :descriptions, :alias_groups, :site_links, :statements
attr_accessor :type, :id, :labels_hash, :descriptions_hash, :alias_groups_hash, :site_links_hash, :statements_hash

def initialize(**kwargs)
@type = ENTITY_TYPE
@id = kwargs[:id]
@labels = kwargs[:labels] || TermList.new
@descriptions = kwargs[:descriptions] || TermList.new
@alias_groups = kwargs[:alias_groups] || AliasGroupList.new
@site_links = kwargs[:site_links] || SiteLinkList.new
@statements = kwargs[:statements] || StatementList.new
@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

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

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

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

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

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

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

def state
[type, id, labels, descriptions, alias_groups, site_links, statements]
[type, id, labels_hash, descriptions_hash, alias_groups_hash, site_links_hash, statements_hash]
end

def ==(other)
Expand All @@ -61,7 +61,7 @@ def eql?(other)
self == other
end

alias claims statements
alias claims_hash statements_hash
alias claims_by_property_id statements_by_property_id
alias claims_by_property_id? statements_by_property_id?
end
Expand Down
18 changes: 9 additions & 9 deletions lib/wikibase_representable/model/property.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'wikibase_representable/model/alias_group_list'
require 'wikibase_representable/model/statement_list'
require 'wikibase_representable/model/term_list'
require 'wikibase_representable/model/alias_group_hash'
require 'wikibase_representable/model/statement_hash'
require 'wikibase_representable/model/term_hash'
require 'wikibase_representable/model/term'

module WikibaseRepresentable
Expand All @@ -11,20 +11,20 @@ module Model
class Property
ENTITY_TYPE = 'property'

attr_accessor :type, :id, :data_type, :labels, :descriptions, :alias_groups, :statements
attr_accessor :type, :id, :data_type, :labels_hash, :descriptions_hash, :alias_groups_hash, :statements_hash

def initialize(**kwargs)
@type = ENTITY_TYPE
@data_type = kwargs[:data_type]
@id = kwargs[:id]
@labels = kwargs[:labels] || TermList.new
@descriptions = kwargs[:descriptions] || TermList.new
@alias_groups = kwargs[:alias_groups] || AliasGroupList.new
@statements = kwargs[:statements] || StatementList.new
@labels_hash = kwargs[:labels_hash] || TermHash.new
@descriptions_hash = kwargs[:descriptions_hash] || TermHash.new
@alias_groups_hash = kwargs[:alias_groups_hash] || AliasGroupHash.new
@statements_hash = kwargs[:statements_hash] || StatementHash.new
end

def state
[type, id, data_type, labels, descriptions, alias_groups, statements]
[type, id, data_type, labels_hash, descriptions_hash, alias_groups_hash, statements_hash]
end

def ==(other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module WikibaseRepresentable
module Model
# Hash of SiteLink objects keyed by site id.
class SiteLinkList < Hash
class SiteLinkHash < Hash
def link_for_site(site_id)
fetch(site_id, nil)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module WikibaseRepresentable
module Model
# Hash of property ID => Snak array.
class SnakList < Hash
# Hash of Snak lists keyed by property ID
class SnakHash < Hash
def snaks_by_property_id(property_id)
fetch(property_id, nil)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/wikibase_representable/model/statement.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'wikibase_representable/model/snak_list'
require 'wikibase_representable/model/snak_hash'

module WikibaseRepresentable
module Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module WikibaseRepresentable
module Model
# Wraps a hash of Statement arrays keyed by entity id.
class StatementList < Hash
# Hash of Statement lists keyed by property id.
class StatementHash < Hash
def statements_by_property_id(property_id)
fetch(property_id, nil)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

module WikibaseRepresentable
module Model
# Wraps a hash of Term objects keyed by language code.
class TermList < Hash
# Hash of Term objects keyed by language code.
class TermHash < Hash
def term_for_language(language_code)
fetch(language_code, nil)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/wikibase_representable/representers.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

require 'wikibase_representable/representers/alias_group_list_representer'
require 'wikibase_representable/representers/alias_group_hash_representer'
require 'wikibase_representable/representers/data_value_representer'
require 'wikibase_representable/representers/entity_id_value_representer'
require 'wikibase_representable/representers/entity_id_representer'
require 'wikibase_representable/representers/item_representer'
require 'wikibase_representable/representers/property_value_snak_representer'
require 'wikibase_representable/representers/property_representer'
require 'wikibase_representable/representers/site_link_list_representer'
require 'wikibase_representable/representers/site_link_hash_representer'
require 'wikibase_representable/representers/site_link_representer'
require 'wikibase_representable/representers/snak_list_representer'
require 'wikibase_representable/representers/statement_list_representer'
require 'wikibase_representable/representers/snak_hash_representer'
require 'wikibase_representable/representers/statement_hash_representer'
require 'wikibase_representable/representers/statement_representer'
require 'wikibase_representable/representers/term_list_representer'
require 'wikibase_representable/representers/term_hash_representer'
require 'wikibase_representable/representers/term_representer'
require 'wikibase_representable/representers/time_value_representer'
require 'wikibase_representable/representers/time_representer'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module WikibaseRepresentable
module Representers
# Representer for a hash of language_codes => term arrays
class AliasGroupListRepresenter < Representable::Decorator
class AliasGroupHashRepresenter < Representable::Decorator
include Representable::JSON::Hash

values decorator: TermRepresenter.for_collection, instance: ->(_fragment) { [] }
Expand Down
33 changes: 16 additions & 17 deletions lib/wikibase_representable/representers/item_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

require 'representable/json'
require 'wikibase_representable/model'
require 'wikibase_representable/representers/alias_group_list_representer'
require 'wikibase_representable/representers/site_link_list_representer'
require 'wikibase_representable/representers/statement_list_representer'
require 'wikibase_representable/representers/term_list_representer'
require 'wikibase_representable/representers/alias_group_hash_representer'
require 'wikibase_representable/representers/site_link_hash_representer'
require 'wikibase_representable/representers/statement_hash_representer'
require 'wikibase_representable/representers/term_hash_representer'

module WikibaseRepresentable
module Representers
Expand All @@ -16,19 +16,18 @@ class ItemRepresenter < Representable::Decorator

property :type
property :id
property :labels, decorator: TermListRepresenter,
class: TermList
property :descriptions, decorator: TermListRepresenter,
class: TermList
property :alias_groups, as: 'aliases',
decorator: AliasGroupListRepresenter,
class: AliasGroupList
property :statements, as: 'claims',
decorator: StatementListRepresenter,
class: StatementList
property :site_links, as: 'sitelinks',
decorator: SiteLinkListRepresenter,
class: SiteLinkList
property :labels_hash, decorator: TermHashRepresenter,
class: TermHash
property :descriptions_hash, decorator: TermHashRepresenter,
class: TermHash
property :alias_groups_hash, as: 'aliases_hash',
decorator: AliasGroupHashRepresenter,
class: AliasGroupHash
property :statements_hash, as: 'claims_hash',
decorator: StatementHashRepresenter,
class: StatementHash
property :site_links_hash, decorator: SiteLinkHashRepresenter,
class: SiteLinkHash
end
end
end
26 changes: 13 additions & 13 deletions lib/wikibase_representable/representers/property_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

require 'representable/json'
require 'wikibase_representable/model'
require 'wikibase_representable/representers/alias_group_list_representer'
require 'wikibase_representable/representers/statement_list_representer'
require 'wikibase_representable/representers/term_list_representer'
require 'wikibase_representable/representers/alias_group_hash_representer'
require 'wikibase_representable/representers/statement_hash_representer'
require 'wikibase_representable/representers/term_hash_representer'

module WikibaseRepresentable
module Representers
Expand All @@ -16,16 +16,16 @@ class PropertyRepresenter < Representable::Decorator
property :type
property :data_type, as: 'datatype'
property :id
property :labels, decorator: TermListRepresenter,
class: TermList
property :descriptions, decorator: TermListRepresenter,
class: TermList
property :alias_groups, as: 'aliases',
decorator: AliasGroupListRepresenter,
class: AliasGroupList
property :statements, as: 'claims',
decorator: StatementListRepresenter,
class: StatementList
property :labels_hash, decorator: TermHashRepresenter,
class: TermHash
property :descriptions_hash, decorator: TermHashRepresenter,
class: TermHash
property :alias_groups_hash, as: 'aliases_hash',
decorator: AliasGroupHashRepresenter,
class: AliasGroupHash
property :statements_hash, as: 'claims_hash',
decorator: StatementHashRepresenter,
class: StatementHash
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module WikibaseRepresentable
module Representers
# Representer for a hash of (siteid => sitelink)
class SiteLinkListRepresenter < Representable::Decorator
class SiteLinkHashRepresenter < Representable::Decorator
include Representable::JSON::Hash
include WikibaseRepresentable::Model

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

module WikibaseRepresentable
module Representers
# Representer for a list of property value snaks.
class SnakListRepresenter < Representable::Decorator
# Representer for a hash of snak lists keyed by property ID.
class SnakHashRepresenter < Representable::Decorator
include Representable::JSON::Hash

values decorator: PropertyValueSnakRepresenter.for_collection, instance: ->(_fragment) { [] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module WikibaseRepresentable
module Representers
# Representer for a hash of property IDs => statement arrays.
class StatementListRepresenter < Representable::Decorator
class StatementHashRepresenter < Representable::Decorator
include Representable::JSON::Hash

values decorator: StatementRepresenter.for_collection, instance: ->(_fragment) { [] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'representable/json'
require 'wikibase_representable/model'
require 'wikibase_representable/representers/property_value_snak_representer'
require 'wikibase_representable/representers/snak_list_representer'
require 'wikibase_representable/representers/snak_hash_representer'

module WikibaseRepresentable
module Representers
Expand All @@ -16,8 +16,8 @@ class StatementRepresenter < Representable::Decorator
decorator: PropertyValueSnakRepresenter,
class: PropertyValueSnak
property :type
property :qualifiers, decorator: SnakListRepresenter,
class: SnakList
property :qualifiers, decorator: SnakHashRepresenter,
class: SnakHash
property :qualifiers_order, as: 'qualifiers-order'
property :guid, as: 'id'
property :rank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

module WikibaseRepresentable
module Representers
# Representer for term lists
class TermListRepresenter < Representable::Decorator
# Representer for term hashes
class TermHashRepresenter < Representable::Decorator
include Representable::JSON::Hash
include WikibaseRepresentable::Model

Expand Down
Loading