Changeset 252 for ruby


Ignore:
Timestamp:
Sep 7, 2009, 8:16:48 PM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

DvProportion moved test/unit to rspec

File:
1 edited

Legend:

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

    r250 r252  
    313313          attr_reader :numerator, :denominator, :type, :precision
    314314
    315           def initialize(numerator, denominator, type, precision=nil,
    316                          magnitude_status=nil, accuracy=nil,
    317                          accuracy_percent=nil, normal_range=nil,
    318                          normal_status = nil, other_reference_ranges=nil)
    319             self.type = type
    320             self.numerator = numerator
    321             self.denominator = denominator
    322             self.precision = precision
    323             self.magnitude_status = magnitude_status
    324             unless accuracy.nil?
    325               set_accuracy(accuracy, accuracy_percent)
     315          def initialize(args = {})
     316            self.type = args[:type]
     317            self.numerator = args[:numerator]
     318            self.denominator = args[:denominator]
     319            self.precision = args[:precision]
     320            self.magnitude_status =args[:magnitude_status]
     321            unless args[:accuracy].nil?
     322              set_accuracy(args[:accuracy], args[:accuracy_percent])
    326323            else
    327324              @accuracy, @accuracy_percent = nil, nil
    328325            end
    329             self.normal_range = normal_range
    330             self.normal_status = normal_status
    331             self.other_reference_ranges = other_reference_ranges
     326            self.normal_range = args[:normal_range]
     327            self.normal_status = args[:normal_status]
     328            self.other_reference_ranges = args[:other_reference_ranges]
    332329          end
    333330
     
    342339
    343340          def denominator=(denominator)
    344             if denominator.nil? or denominator == PK_RATIO
    345               raise ArgumentError, 'denominator invalid'
    346             end
    347             if (@type == PK_FRACTION || @type == PK_INTEGER_FRACTION) &&
    348                 !denominator.integer?
    349               raise ArgumentError, 'denominator invalid for type'
    350             end
    351             if @type == PK_UNITARY && denominator != 1
    352               raise ArgumentError, 'denominator invalid for type'
    353             end
    354             if @type == PK_PERCENT && denominator != 100
    355               raise ArgumentError, 'denominator invaild for type'
     341            case @type
     342            when PK_UNITARY
     343              unless denominator == 1
     344                raise ArgumentError, 'Unitary denominator must be 1'
     345              end
     346            when PK_PERCENT
     347              unless denominator == 100
     348                raise ArgumentError, 'Percent denominator must be 100'
     349              end
     350            when PK_FRACTION, PK_INTEGER_FRACTION
     351              unless denominator.integer? and @numerator.integer?
     352                raise ArgumentError, 'Fraction numerator/denominator must be integer'
     353              end
    356354            end
    357355            @denominator = denominator
     
    372370          def precision=(precision)
    373371            unless precision.nil?
    374               unless precision == 0 || self.is_integral?
    375                 @precision = precision
    376               else
     372              if (self.is_integral? && precision !=0)
    377373                raise ArgumentError, 'precision invalid'
    378374              end
    379375            end
     376            @precision = precision
    380377          end
    381378
     
    385382
    386383          def is_strictly_comparable_to?(other)
    387             unless other.instance_of?(DvProportion)
     384            unless super(other)
    388385              return false
    389386            end
Note: See TracChangeset for help on using the changeset viewer.