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.



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

#accuracyObject (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_percentObject (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



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

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

Instance Method Details

#+(other) ⇒ Object



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

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



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

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

#-@Object



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

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

#accuracy_is_percent?Boolean

Returns:

  • (Boolean)


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

def accuracy_is_percent?
  return @accuracy_percent
end

#set_accuracy(accuracy, accuracy_percent) ⇒ Object



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

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