Class: Wikidatum::DataType::MonolingualText

Inherits:
Object
  • Object
show all
Defined in:
lib/wikidatum/data_type/monolingual_text.rb

Overview

The Monolingual Text type JSON looks like this:

{
  "property": {
    "id": "P13432",
    "data-type": "monolingualtext"
  },
  "value": {
    "type": "value",
    "content": {
      "text": "foo",
      "language": "en-gb"
    }
  }
}

Defined Under Namespace

Classes: HumanizedStruct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language:, text:) ⇒ void

Parameters:

  • language (String)
  • text (String)


32
33
34
35
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 32

def initialize(language:, text:)
  @language = language
  @text = text
end

Instance Attribute Details

#languageString (readonly)

Returns the language code, e.g. ‘en’.

Returns:

  • (String)

    the language code, e.g. ‘en’



24
25
26
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 24

def language
  @language
end

#textString (readonly)

Returns:

  • (String)


27
28
29
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 27

def text
  @text
end

Class Method Details

.symbolized_nameSymbol

Returns:

  • (Symbol)


63
64
65
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 63

def self.symbolized_name
  :monolingual_text
end

Instance Method Details

#humanizedHumanizedStruct<language, text>

The content of the data value object. Use this to get a more sensible representation of the statement’s contents.



58
59
60
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 58

def humanized
  HumanizedStruct.new(to_h)
end

#to_hHash

Returns:

  • (Hash)


38
39
40
41
42
43
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 38

def to_h
  {
    language: @language,
    text: @text
  }
end

#wikibase_typeString

The “type” value used by Wikibase, for use when creating/updating statements.

Returns:

  • (String)


48
49
50
# File 'lib/wikidatum/data_type/monolingual_text.rb', line 48

def wikibase_type
  'monolingualtext'
end