Index: ruby/trunk/archetype
===================================================================
--- ruby/trunk/archetype	(revision 3)
+++ ruby/trunk/archetype	(revision 3)
@@ -0,0 +1,146 @@
+#! /usr/bin/env ruby
+# component: openEHR Ruby reference implementation
+# description: This file includes Archetype 
+#      class that contains Archetype values.
+#      Main concept is based on Java ref impl.
+#      We should make refactoring to suit for Ruby way.
+# keywords: archetype
+# author: Shinji KOBAYASHI
+# support: openEHR.jp
+# license: openEHR open source license
+#
+require 'set'
+class Archetype < AuthordResource
+  attr_reader :adlVersion, :id, :parentId
+  attr_reader :concept, :definition, :ontology
+  attr_accessor :description, :isControled, :originalLanguage
+  attr_accessor :revisionHistory, :translation
+  def initialize(adlVersion, id = nil , parentId, concept
+                 originalLanguage = nil, translation = nil
+                 description, revisionHistory, isControled
+                 defitnition, ontology)
+    if id == nil
+      raise Exception.new("illegal argument error, id == nil")
+    end
+    if originalLanguage == nil
+      raise Exception.new("illegal argument error, originalLanguage == nil")
+    end
+    if translation == nil
+      raise Exception.new("illegal argument error, translation == nil")
+    end
+    @adlVersion = adlVersion
+    @id = id
+    @parentId = parentId
+    @concept = concept
+    @originalLanguage = originalLanguage
+    @translation = translation
+    @description = description
+    @revisionHistory = revisionHistory
+    @isControled = isControled
+    @defitnition = defitnition
+    @ontology = ontology
+    loadMaps(definition)
+  end
+  
+end
+class AuthoredResource
+  attr_reader :is_controled
+  attr_reader :revision_history, :translations
+  attr_accessor :description, :original_language
+  def initialize(original_language, translations, 
+                 description, revision_history = nil)
+    if original_language == nil
+      raise Exception.new("original language nil")
+    end
+    if translations == nil
+      raise Exception.new("translation empty")
+    end
+    if revision_history == nil
+      is_controled = false
+    else
+      is_controled = true
+    end
+    @original_language = original_language
+    @translations = translations
+    @description = description
+    @revision_history = revision_history
+  end
+  def current_version
+    @revision_history.most_recent_revision
+  end
+  def language_available
+    languages = Set.new
+    if translations != nil
+      languages << translations.keys
+    end
+    languages << original_language.code_string
+  end
+end
+class RevisionHistory
+end
+class CodePhrase
+  attr_reader :terminology_id, :code_string
+  def initialize(terminology_id, codeString)
+    if terminlogyID == nil
+      raise Exception.new("nil terminology")
+    end
+    if codeString == nil
+      raise Exception.new("empty codeString")
+    end
+    if terminology_id.instance_of?(TerminologyID)
+      @terminology_id = terminology_id
+    else
+      @terminologyID = TerminologyID.new(terminology_id)
+    end
+    @code_string = code_string
+  end
+end
+
+class TerminologyID < ObjectID
+  attr_reader :name
+  def initialize(arg0, arg1=nil)
+    if arg1 == nil
+      super(arg0)
+    else
+      super(toValue(arg0, arg1))
+      @name = arg0
+      @version = arg1      
+    end
+  end
+  def setValue(value)
+    loadValue(value)
+    super.value = value
+  end
+  def version_id
+    @version
+  end
+  private
+  def loadValue(value)
+    if /\(.*\)$/ =~ value
+      @name, @version = value.split(\())
+      @version.chop!
+    else
+      @name = value
+      @version = nil
+    end
+  end
+
+  def toValue(name, version)
+    if name == ""
+      raise Exception.new("empty name")
+    end
+    name + (version == nil ? "" : "(" + version + ")")
+  end
+end
+
+# Ancestor class of identification class
+#
+class ObjectID
+  attr_accessor :value
+  def initiallize(value)
+    if value == nil
+      raise Exception.new("empty value")
+    end
+    @value = value
+  end
+end
