Class: Wikidatum::DataType::Quantity
- Inherits:
-
Object
- Object
- Wikidatum::DataType::Quantity
- 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
-
#amount ⇒ String
readonly
A string value like “+2”, usually an integer but not always.
-
#unit ⇒ String
readonly
A URL describing the unit for this quantity, e.g.
Class Method Summary collapse
Instance Method Summary collapse
-
#humanized ⇒ HumanizedStruct<amount, unit>
The content of the data value object.
- #initialize(amount:, unit:) ⇒ void constructor
- #to_h ⇒ Hash
-
#wikibase_type ⇒ String
The “type” value used by Wikibase, for use when creating/updating statements.
Constructor Details
#initialize(amount:, unit:) ⇒ void
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
#amount ⇒ String (readonly)
Returns 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 |
#unit ⇒ String (readonly)
Returns 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_name ⇒ Symbol
63 64 65 |
# File 'lib/wikidatum/data_type/quantity.rb', line 63 def self.symbolized_name :quantity end |
Instance Method Details
#humanized ⇒ HumanizedStruct<amount, unit>
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/quantity.rb', line 58 def humanized HumanizedStruct.new(to_h) end |
#to_h ⇒ 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_type ⇒ String
The “type” value used by Wikibase, for use when creating/updating statements.
48 49 50 |
# File 'lib/wikidatum/data_type/quantity.rb', line 48 def wikibase_type 'quantity' end |