Changeset 94 for ruby/trunk


Ignore:
Timestamp:
Jul 29, 2008, 11:56:32 PM (16 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #39
fixed Object_Ref, Object_ID

Location:
ruby/trunk/lib/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/lib/models/rm/support/identification.rb

    r93 r94  
    1818            @value = value           
    1919          end
     20          def ==(object_id)
     21            @value == object_id.value
     22          end
    2023        end # of ObjectID
     24
     25        class Object_Ref
     26          attr_reader :namespace, :type, :id
     27
     28          def initialize(namespace, type, id)
     29            self.namespace = namespace
     30            self.type = type
     31            self.id = id
     32          end
     33
     34          def namespace=(namespace)
     35            raise ArgumentError if namespace.nil? or namespace.empty? or !(/([a-z]|[A-Z]).*/ =~ namespace) # error original is =~ #([a-z][A-Z])([a-z]|[A-Z]|\s|[0-9]|[_-\:\/\&\+\?])*/
     36            @namespace = namespace
     37          end
     38
     39          def type=(type)
     40            raise ArgumentError if type.nil? or type.empty?
     41            @type = type
     42          end
     43
     44          def id=(id)
     45            raise ArgumentError if id.nil?
     46            @id = id
     47          end
     48        end
    2149       
    2250        class Archetype_ID < Object_ID
     
    96124          end
    97125        end # of Generic_ID
     126
    98127        class UID_Based_ID < Object_ID
    99128          def initialize(value)
  • ruby/trunk/lib/models/tests/test_reference_model.rb

    r93 r94  
    147147  def setup
    148148    assert_nothing_raised(Exception){@object_id = OpenEHR::RM::Support::Identification::Object_ID.new("0.0.3")}
     149    assert_nothing_raised(Exception){@object_ref = OpenEHR::RM::Support::Identification::Object_Ref.new('local', 'ANY', @object_id)}
    149150    assert_nothing_raised(Exception){@archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
    150151    assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", 'terminology','0.0.3')}
     
    155156  def test_init
    156157    assert_instance_of OpenEHR::RM::Support::Identification::Object_ID, @object_id
     158    assert_instance_of OpenEHR::RM::Support::Identification::Object_Ref, @object_ref
    157159    assert_instance_of OpenEHR::RM::Support::Identification::Archetype_ID, @archetype_id
    158160    assert_instance_of OpenEHR::RM::Support::Identification::Terminology_ID, @terminology_id
     
    170172    assert_raise(ArgumentError){@object_id = OpenEHR::RM::Support::Identification::Object_ID.new(nil)}
    171173    assert_raise(ArgumentError){@object_id = OpenEHR::RM::Support::Identification::Object_ID.new("")}
     174  end
     175
     176  def test_object_refs
     177    assert_equal 'local', @object_ref.namespace
     178    assert_equal 'ANY', @object_ref.type
     179    assert_equal @object_id, @object_ref.id
     180
     181    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new}
     182    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new(nil, 'ANY', @object_id)}
     183    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new('', 'ANY', @object_id)}
     184    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new('local', nil, @object_id)}
     185    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new('local', '', @object_id)}
     186    assert_raise(ArgumentError){@object_ref = OpenEHR::RM::Support::Identification::Archetype_ID.new('local', 'ANY', nil)}
     187
     188    assert_nothing_raised(Exception){@object_ref.namespace = 'terminology'}
     189    assert_equal 'terminology', @object_ref.namespace
     190    assert_raise(ArgumentError){@object_ref.namespace = nil}
     191    assert_raise(ArgumentError){@object_ref.namespace = ''}
     192    assert_raise(ArgumentError){@object_ref.namespace = '?&&'}
     193    assert_raise(ArgumentError){@object_ref.namespace = '843'}
     194
     195    assert_nothing_raised(Exception){@object_ref.type = 'GUIDELINE'}
     196    assert_equal 'GUIDELINE', @object_ref.type
     197    assert_raise(ArgumentError){@object_ref.type = nil}
     198    assert_raise(ArgumentError){@object_ref.type = ''}
     199
     200    assert_nothing_raised(Exception){@object_ref.id = OpenEHR::RM::Support::Identification::Object_ID.new("0.0.5")}
     201    assert_equal OpenEHR::RM::Support::Identification::Object_ID.new("0.0.5"), @object_ref.id
     202    assert_raise(ArgumentError){@object_ref.id = nil}
    172203  end
    173204
Note: See TracChangeset for help on using the changeset viewer.