Class: Wikidatum::DataType::Base

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

Direct Known Subclasses

NoValue, SomeValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, content:) ⇒ void



37
38
39
40
# File 'lib/wikidatum/data_type/base.rb', line 37

def initialize(type:, content:)
  @type = type
  @content = content
end

Instance Attribute Details

#contentDataType::CommonsMedia, ... (readonly)

The value of the “content” attribute in the response.

If the type is :no_value or :some_value, this returns nil.



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

def content
  @content
end

#typeSymbol (readonly)

Represents the type for this instance.

Possible values for the type attribute are:

Returns:

  • (Symbol)


25
26
27
# File 'lib/wikidatum/data_type/base.rb', line 25

def type
  @type
end

Instance Method Details

#humanized_contentString, ...

Get the humanized version of the content. Depending on the given data type, it will return values in different formats.



54
55
56
# File 'lib/wikidatum/data_type/base.rb', line 54

def humanized_content
  @content.humanized
end

#to_hHash

Returns:

  • (Hash)


43
44
45
46
47
48
# File 'lib/wikidatum/data_type/base.rb', line 43

def to_h
  {
    type: @type,
    content: @content&.to_h
  }
end