Index: ruby/branches/0.5/lib/open_ehr/rm/support/identification.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/rm/support/identification.rb	(revision 273)
+++ ruby/branches/0.5/lib/open_ehr/rm/support/identification.rb	(revision 274)
@@ -316,13 +316,12 @@
 
         class VersionTreeID
-          attr_reader :value, :trunk_version, :branch_number, :branch_version
-
-          def initialize(value)
-            self.value = value
+          attr_reader :trunk_version, :branch_number, :branch_version
+
+          def initialize(args = {})
+            self.value = args[:value]
           end
 
           def value=(value)
             raise ArgumentError, 'value invalid' if value.nil? or value.empty?
-            @trunk_version = @branch_number = @branch_version = nil
             (trunk_version, branch_number, branch_version) = value.split '.'
             self.trunk_version = trunk_version
@@ -331,34 +330,39 @@
           end
 
-          def trunk_version=(trunk_version)
-            raise ArgumentError, 'trunk_version invalid' if trunk_version.nil? and !trunk_version.to_i >= 1
-            @trunk_version = trunk_version
-            set_value
-          end
-
-          def branch_number=(branch_number)
-            raise ArgumentError, 'branch number invalid' unless branch_number.nil? or branch_number.to_i >= 1
-            @branch_number = branch_number
-            set_value
-          end
-
-          def branch_version=(branch_version)
-            raise ArgumentError, 'branch version invalid' if (!branch_version.nil? and !( branch_version.to_i >= 1)) or (!branch_version.nil? and @branch_number.nil?)
-            @branch_version = branch_version
-            set_value
-          end
-          def is_branch?
-            !@branch_version.nil? and !@branch_number.nil?
-          end
-
-          def is_first?
-            trunk_version == '1'
-          end
-
-          private
-          def set_value
+          def value
             @value = trunk_version
             @value = @value + '.' + @branch_number unless @branch_number.nil?
             @value = @value + '.' + @branch_version unless @branch_version.nil?
+            return @value
+          end
+
+          def trunk_version=(trunk_version)
+            if trunk_version.nil? || (trunk_version.to_i < 1)
+              raise ArgumentError, 'trunk_version invalid'
+            end
+            @trunk_version = trunk_version
+          end
+
+          def branch_number=(branch_number)
+            unless branch_number.nil? or branch_number.to_i >= 1
+              raise ArgumentError, 'branch number invalid'
+            end
+            @branch_number = branch_number
+          end
+
+          def branch_version=(branch_version)
+            if (!branch_version.nil? and !(branch_version.to_i >= 1)) or
+                (!branch_version.nil? and @branch_number.nil?)
+              raise ArgumentError, 'branch version invalid'
+            end
+            @branch_version = branch_version
+          end
+
+          def is_branch?
+            !@branch_version.nil? and !@branch_number.nil?
+          end
+
+          def is_first?
+            trunk_version == '1'
           end
         end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/support/identification/version_tree_id_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/support/identification/version_tree_id_spec.rb	(revision 274)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/support/identification/version_tree_id_spec.rb	(revision 274)
@@ -0,0 +1,104 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::Support::Identification
+
+describe VersionTreeID do
+  before(:each) do
+    @version_tree_id = VersionTreeID.new(:value => '1.2.3')
+  end
+
+  it 'should be an instance of VersionTreeID' do
+    @version_tree_id.should be_an_instance_of VersionTreeID
+  end
+
+  it 'value should be 1.2.3' do
+    @version_tree_id.value.should == '1.2.3'
+  end
+
+  it 'trunk_version should 1' do
+    @version_tree_id.trunk_version.should == '1'
+  end
+
+  it 'branch_number should 2' do
+    @version_tree_id.branch_number.should == '2'
+  end
+
+  it 'branch_version should 3' do
+    @version_tree_id.branch_version.should == '3'
+  end
+
+  it 'is_first? should be true' do
+    @version_tree_id.is_first?.should be_true
+  end
+
+  it 'is_branch? should be true' do
+    @version_tree_id.is_branch?.should be_true
+  end
+
+  it 'should raise ArgumentError with nil trunk version' do
+    lambda {
+      @version_tree_id.trunk_version = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with 0 trunk version' do
+    lambda {
+      @version_tree_id.trunk_version = 0
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with 0 branch number' do
+    lambda {
+      @version_tree_id.branch_number = 0
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with 0 branch version' do
+    lambda {
+      @version_tree_id.branch_version = 0
+    }.should raise_error ArgumentError
+  end
+
+  describe 'partial version tree id' do
+    describe 'version 4.5' do
+      before(:each) do
+        @version_tree_id = VersionTreeID.new(:value => '4.5')
+      end
+
+      it 'value should be 4.5' do
+        @version_tree_id.value.should == '4.5'
+      end
+
+      it 'should be nil branch version' do
+        @version_tree_id.branch_version.should be_nil
+      end
+
+      it 'is_first? should not be true' do
+        @version_tree_id.is_first?.should_not be_true
+      end
+    end
+
+    describe 'version 6' do
+      before(:each) do
+        @version_tree_id = VersionTreeID.new(:value => '6')
+      end
+
+      it 'value should be 6' do
+        @version_tree_id.value.should == '6'
+      end
+
+      it 'should be nil branch number' do
+        @version_tree_id.branch_number.should be_nil
+      end
+
+      it 'is_branch should not be true' do
+        @version_tree_id.is_branch?.should_not be_true
+      end
+
+      it 'should raise ArgumentError if assinged branch version' do
+        lambda {
+          @version_tree_id.branch_version = '7'
+        }.should raise_error ArgumentError
+      end
+    end
+  end
+end
