Class: Wikidatum::DataType::Quantity

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

Overview

The Quantity type JSON looks like this:

{
  "property": {
    "id": "P937",
    "data-type": "quantity"
  },
  "value": {
    "type": "value",
    "content": {
      "amount": "+15",
      "unit": "1"
    }
  }
}

Defined Under Namespace

Classes: HumanizedStruct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, unit:) ⇒ void

Parameters:

  • amount (String)
  • unit (String)


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

def initialize(amount:, unit:)
  @amount = amount
  @unit = unit
end

Instance Attribute Details

#amountString (readonly)

Returns A string value like “+2”, usually an integer but not always.

Returns:

  • (String)

    A string value like “+2”, usually an integer but not always.



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

def amount
  @amount
end

#unitString (readonly)

Returns a URL describing the unit for this quantity, e.g. “meter”, “kilometer”, “pound”, “chapter”, “section”, etc.

Returns:

  • (String)

    a URL describing the unit for this quantity, e.g. “meter”, “kilometer”, “pound”, “chapter”, “section”, etc.



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

def unit
  @unit
end

Class Method Details

.symbolized_nameSymbol

Returns:

  • (Symbol)


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

def self.symbolized_name
  :quantity
end

Instance Method Details

#humanizedHumanizedStruct<amount, unit>

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

Returns:



58
59
60
# File 'lib/wikidatum/data_type/quantity.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/quantity.rb', line 38

def to_h
  {
    amount: @amount,
    unit: @unit
  }
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/quantity.rb', line 48

def wikibase_type
  'quantity'
end