Changeset 249 for ruby/branches


Ignore:
Timestamp:
Sep 7, 2009, 1:38:31 PM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

move DvAbsoluteQuantity test to spec

Location:
ruby/branches/0.5
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity.rb

    r248 r249  
    129129          end
    130130          def is_strictly_comparable_to?(others)
    131             super
    132             unless others.instance_of? self.class
     131            unless super(others)
    133132              return false
    134133            end
     
    145144          attr_accessor :accuracy
    146145
    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)
    152148            self.accuracy = accuracy
    153149          end
    154150
    155151          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)
    157155          end
    158156
    159157          def diff(other)
    160             raise NotImplementedError, 'diff must be implemented'
     158            type_check(other)
     159            return result_builder(DvAmount,
     160                                  (@magnitude-other.magnitude).abs)
    161161          end
    162162
    163163          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)
    165183          end
    166184        end
Note: See TracChangeset for help on using the changeset viewer.