Class: OpenEHR::RM::DataTypes::Quantity::DvProportion
- Inherits:
-
DvAmount
- Object
- Basic::DataValue
- DvOrdered
- DvQuantified
- DvAmount
- OpenEHR::RM::DataTypes::Quantity::DvProportion
- Includes:
- ProportionKind
- Defined in:
- lib/openehr/rm/data_types/quantity.rb
Overview
end of ProportionKind
Constant Summary
Constants included from ProportionKind
ProportionKind::PK_FRACTION, ProportionKind::PK_INTEGER_FRACTION, ProportionKind::PK_PERCENT, ProportionKind::PK_RATIO, ProportionKind::PK_UNITARY
Constants included from Support::Definition::BasicDefinition
Support::Definition::BasicDefinition::CR, Support::Definition::BasicDefinition::LF
Instance Attribute Summary collapse
-
#denominator ⇒ Object
Returns the value of attribute denominator.
-
#numerator ⇒ Object
Returns the value of attribute numerator.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from DvAmount
Attributes inherited from DvQuantified
Attributes inherited from DvOrdered
#normal_range, #normal_status, #other_reference_ranges
Attributes inherited from Basic::DataValue
Instance Method Summary collapse
-
#+(other) ⇒ Object
DvProportion's magnitude is derived from numerator/denominator rather than ivar-backed, so it cannot use DvAmount's default build_arithmetic_result (magnitude=-based reconstruction) - +/-@/multiply are overridden here at the numerator/denominator level instead.
- #-(other) ⇒ Object
- #-@ ⇒ Object
-
#initialize(args = {}) ⇒ DvProportion
constructor
A new instance of DvProportion.
- #is_integral? ⇒ Boolean
- #is_strictly_comparable_to?(other) ⇒ Boolean
- #magnitude ⇒ Object
- #multiply(factor) ⇒ Object (also: #*)
Methods inherited from DvAmount
#accuracy_is_percent?, #set_accuracy, valid_percentage
Methods inherited from DvQuantified
#<=>, #accuracy_unknown?, valid_magnitude_status?
Methods inherited from DvOrdered
#<=>, #is_normal?, #is_simple?
Methods inherited from Basic::DataValue
Constructor Details
#initialize(args = {}) ⇒ DvProportion
Returns a new instance of DvProportion.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 389 def initialize(args = {}) self.type = args[:type] self.numerator = args[:numerator] self.denominator = args[:denominator] self.precision = args[:precision] self.magnitude_status =args[:magnitude_status] unless args[:accuracy].nil? set_accuracy(args[:accuracy], args[:accuracy_percent]) else @accuracy, @accuracy_percent = nil, nil end self.normal_range = args[:normal_range] self.normal_status = args[:normal_status] self.other_reference_ranges = args[:other_reference_ranges] end |
Instance Attribute Details
#denominator ⇒ Object
Returns the value of attribute denominator.
387 388 389 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 387 def denominator @denominator end |
#numerator ⇒ Object
Returns the value of attribute numerator.
387 388 389 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 387 def numerator @numerator end |
#precision ⇒ Object
Returns the value of attribute precision.
387 388 389 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 387 def precision @precision end |
#type ⇒ Object
Returns the value of attribute type.
387 388 389 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 387 def type @type end |
Instance Method Details
#+(other) ⇒ Object
DvProportion's magnitude is derived from numerator/denominator rather than ivar-backed, so it cannot use DvAmount's default build_arithmetic_result (magnitude=-based reconstruction) - +/-@/multiply are overridden here at the numerator/denominator level instead. Only same-denominator addition/subtraction is well-defined without inventing a fraction-normalization policy beyond what the RM specifies.
475 476 477 478 479 480 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 475 def +(other) unless is_strictly_comparable_to?(other) && denominator == other.denominator raise ArgumentError, 'type mismatch: proportions must share type and denominator' end build_arithmetic_result(numerator + other.numerator) end |
#-(other) ⇒ Object
482 483 484 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 482 def -(other) self + (-other) end |
#-@ ⇒ Object
486 487 488 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 486 def -@ build_arithmetic_result(-numerator) end |
#is_integral? ⇒ Boolean
453 454 455 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 453 def is_integral? return denominator.integer? && numerator.integer? end |
#is_strictly_comparable_to?(other) ⇒ Boolean
457 458 459 460 461 462 463 464 465 466 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 457 def is_strictly_comparable_to?(other) unless super(other) return false end if other.type == @type return true else return false end end |
#magnitude ⇒ Object
440 441 442 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 440 def magnitude return numerator.to_f/denominator.to_f end |
#multiply(factor) ⇒ Object Also known as: *
490 491 492 493 494 |
# File 'lib/openehr/rm/data_types/quantity.rb', line 490 def multiply(factor) raise ArgumentError, 'factor must be Numeric' unless factor.is_a?(Numeric) build_arithmetic_result(numerator * factor) end |