Class: OpenEHR::RM::DataTypes::Quantity::DvAmount

Inherits:
DvQuantified show all
Defined in:
lib/openehr/rm/data_types/quantity.rb

Direct Known Subclasses

DvCount, DvProportion, DvQuantity

Constant Summary

Constants included from Support::Definition::BasicDefinition

Support::Definition::BasicDefinition::CR, Support::Definition::BasicDefinition::LF

Instance Attribute Summary collapse

Attributes inherited from DvQuantified

#magnitude, #magnitude_status

Attributes inherited from DvOrdered

#normal_range, #normal_status, #other_reference_ranges

Attributes inherited from Basic::DataValue

#value

Instance Method Summary collapse

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.



192
193
194
195
196
197
198
199
# File 'lib/openehr/rm/data_types/quantity.rb', line 192

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

#accuracyObject (readonly)

Returns the value of attribute accuracy.



190
191
192
# File 'lib/openehr/rm/data_types/quantity.rb', line 190

def accuracy
  @accuracy
end

#accuracy_percentObject (readonly)

Returns the value of attribute accuracy_percent.



190
191
192
# File 'lib/openehr/rm/data_types/quantity.rb', line 190

def accuracy_percent
  @accuracy_percent
end

Instance Method Details

#+(other) ⇒ Object



201
202
203
204
205
206
207
208
# File 'lib/openehr/rm/data_types/quantity.rb', line 201

def +(other)
  unless self.is_strictly_comparable_to? other
    raise ArgumentError, 'type mismatch'
  end
  result = self.dup
  result.magnitude = @magnitude + other.magnitude
  return result
end

#-(other) ⇒ Object



210
211
212
213
# File 'lib/openehr/rm/data_types/quantity.rb', line 210

def -(other)            
  other.magnitude = - other.magnitude
  self+(other)
end

#accuracy_is_percent?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/openehr/rm/data_types/quantity.rb', line 224

def accuracy_is_percent?
  return @accuracy_percent
end

#set_accuracy(accuracy, accuracy_percent) ⇒ Object



215
216
217
218
219
220
221
222
# File 'lib/openehr/rm/data_types/quantity.rb', line 215

def set_accuracy(accuracy, accuracy_percent)
  if accuracy_percent
    raise ArgumentError, 'accuracy invalid' if accuracy < 0.0 || accuracy > 100.0
  else
    raise ArgumentError, 'accuracy invaild' if accuracy < 0.0 || accuracy > 1.0
  end
  @accuracy, @accuracy_percent = accuracy, accuracy_percent
end