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

Class Method Summary collapse

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.



226
227
228
229
230
231
232
233
# File 'lib/openehr/rm/data_types/quantity.rb', line 226

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.



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

def accuracy
  @accuracy
end

#accuracy_percentObject (readonly)

Returns the value of attribute accuracy_percent.



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

def accuracy_percent
  @accuracy_percent
end

Class Method Details

.valid_percentage(number) ⇒ Object



269
270
271
# File 'lib/openehr/rm/data_types/quantity.rb', line 269

def self.valid_percentage(number)
  number >= 0.0 && number <= 100.0
end

Instance Method Details

#+(other) ⇒ Object



235
236
237
238
239
240
241
242
# File 'lib/openehr/rm/data_types/quantity.rb', line 235

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



244
245
246
247
248
# File 'lib/openehr/rm/data_types/quantity.rb', line 244

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

#-@Object



250
251
252
253
254
# File 'lib/openehr/rm/data_types/quantity.rb', line 250

def -@
  negated = self.dup
  negated.magnitude = -magnitude
  negated
end

#accuracy_is_percent?Boolean

Returns:

  • (Boolean)


265
266
267
# File 'lib/openehr/rm/data_types/quantity.rb', line 265

def accuracy_is_percent?
  return @accuracy_percent
end

#set_accuracy(accuracy, accuracy_percent) ⇒ Object



256
257
258
259
260
261
262
263
# File 'lib/openehr/rm/data_types/quantity.rb', line 256

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