Changeset 249 for ruby/branches/0.5/lib/open_ehr/rm
- Timestamp:
- Sep 7, 2009, 1:38:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity.rb
r248 r249 129 129 end 130 130 def is_strictly_comparable_to?(others) 131 super 132 unless others.instance_of? self.class 131 unless super(others) 133 132 return false 134 133 end … … 145 144 attr_accessor :accuracy 146 145 147 def initialize(magnitude, magnitude_status=nil, accuracy=nil, 148 normal_range=nil, normal_status = nil, 149 other_reference_ranges=nil) 150 super(magnitude, magnitude_status, normal_range, 151 normal_status, other_reference_ranges) 146 def initialize(args = {}) 147 super(args) 152 148 self.accuracy = accuracy 153 149 end 154 150 155 151 def add(a_diff) 156 raise NotImplementedError, 'add must be implemented' 152 type_check(a_diff) 153 return result_builder(DvAbsoluteQuantity, 154 @magnitude+a_diff.magnitude) 157 155 end 158 156 159 157 def diff(other) 160 raise NotImplementedError, 'diff must be implemented' 158 type_check(other) 159 return result_builder(DvAmount, 160 (@magnitude-other.magnitude).abs) 161 161 end 162 162 163 163 def subtract(a_diff) 164 raise NotImplementedError, 'subtract must be implemented' 164 type_check(a_diff) 165 return result_builder(DvAbsoluteQuantity, 166 @magnitude-a_diff.magnitude) 167 end 168 private 169 def type_check(other) 170 unless self.is_strictly_comparable_to? other 171 raise ArgumentError, 'type mismatch' 172 end 173 end 174 175 def result_builder(klass, magnitude) 176 return klass.new(:magnitude => magnitude, 177 :magnitude_status => @magnitude_status, 178 :accuracy => @accuracy, 179 :accuracy_percent => @accuracy_percent, 180 :normal_range => @normal_range, 181 :normal_status => @normal_status, 182 :other_reference_ranges => @other_reference_ranges) 165 183 end 166 184 end
Note:
See TracChangeset
for help on using the changeset viewer.