Class: OpenEHR::RM::DataTypes::Quantity::DvAmount
- Inherits:
-
DvQuantified
- Object
- Basic::DataValue
- DvOrdered
- DvQuantified
- OpenEHR::RM::DataTypes::Quantity::DvAmount
- Defined in:
- lib/openehr/rm/data_types/quantity.rb
Direct Known Subclasses
Constant Summary
Constants included from Support::Definition::BasicDefinition
Support::Definition::BasicDefinition::CR, Support::Definition::BasicDefinition::LF
Instance Attribute Summary collapse
-
#accuracy ⇒ Object
readonly
Returns the value of attribute accuracy.
-
#accuracy_percent ⇒ Object
readonly
Returns the value of attribute accuracy_percent.
Attributes inherited from DvQuantified
Attributes inherited from DvOrdered
#normal_range, #normal_status, #other_reference_ranges
Attributes inherited from Basic::DataValue
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #accuracy_is_percent? ⇒ Boolean
-
#initialize(args = {}) ⇒ DvAmount
constructor
A new instance of DvAmount.
- #multiply(factor) ⇒ Object (also: #*)
- #set_accuracy(accuracy, accuracy_percent) ⇒ Object
Methods inherited from DvQuantified
#<=>, #accuracy_unknown?, valid_magnitude_status?
Methods inherited from DvOrdered
#<=>, #is_normal?, #is_simple?, #is_strictly_comparable_to?
Methods inherited from Basic::DataValue
Constructor Details
#initialize(args = {}) ⇒ DvAmount
Returns a new instance of DvAmount.
227 228 229 230 231 232 233 234 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 227 def initialize(args = {}) super(args) unless args[:accuracy].nil? set_accuracy(args[:accuracy], args[:accuracy_percent]) else @accuracy, @accuracy_percent = nil, nil end end |
Instance Attribute Details
#accuracy ⇒ Object (readonly)
Returns the value of attribute accuracy.
225 226 227 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 225 def accuracy @accuracy end |
#accuracy_percent ⇒ Object (readonly)
Returns the value of attribute accuracy_percent.
225 226 227 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 225 def accuracy_percent @accuracy_percent end |
Class Method Details
.valid_percentage(number) ⇒ Object
274 275 276 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 274 def self.valid_percentage(number) number >= 0.0 && number <= 100.0 end |
Instance Method Details
#+(other) ⇒ Object
236 237 238 239 240 241 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 236 def +(other) unless self.is_strictly_comparable_to? other raise ArgumentError, 'type mismatch' end build_arithmetic_result(magnitude + other.magnitude) end |
#-(other) ⇒ Object
243 244 245 246 247 248 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 243 def -(other) unless self.is_strictly_comparable_to? other raise ArgumentError, 'type mismatch' end build_arithmetic_result(magnitude - other.magnitude) end |
#-@ ⇒ Object
250 251 252 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 250 def -@ build_arithmetic_result(-magnitude) end |
#accuracy_is_percent? ⇒ Boolean
270 271 272 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 270 def accuracy_is_percent? return @accuracy_percent end |
#multiply(factor) ⇒ Object Also known as: *
254 255 256 257 258 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 254 def multiply(factor) raise ArgumentError, 'factor must be Numeric' unless factor.is_a?(Numeric) build_arithmetic_result(magnitude * factor) end |
#set_accuracy(accuracy, accuracy_percent) ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 261 def set_accuracy(accuracy, accuracy_percent) if accuracy_percent raise ArgumentError, 'accuracy invalid' unless self.class.valid_percentage(accuracy) else raise ArgumentError, 'accuracy invaild' if accuracy < 0.0 || accuracy > 1.0 end @accuracy, @accuracy_percent = accuracy, accuracy_percent end |