# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 module RTM::IO # Each Topic Maps Construct gets a custom to_s method which supports optional :short or :long output. module ToString module Construct def delocatorized(identifier_list) identifier_list.map do |locator| locator.value end.inspect end end module TopicMap # Returns different String representations. Try :short (default), :long, :super (original) def to_s(style=:short) case style when :short "#" when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{item_identifiers.to_s}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Topic # Returns different String representations. Try :short (default), :long or something else for the original method. # :name returns one (random) name for the Topic or an empty string if the topic has no name def to_s(style=:short) case style when :short ssid = " sids=#{delocatorized subject_identifiers}" unless subject_identifiers.empty? sslo = " slos=#{delocatorized subject_locators}" unless subject_locators.empty? siid = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" when :long ssid = " sids=#{delocatorized subject_identifiers}" unless subject_identifiers.empty? sslo = " slos=#{delocatorized subject_locators}" unless subject_locators.empty? siid = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" when :name return names.first.to_s(:short) if names.first return "" else super() # these () are needed, otherwise the own parameters are passed in end end end module Association def to_s(style=:short) case style when :short r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Role def to_s(style=:short) case style when :short r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Name def to_s(style=:short) case style when :short value when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Occurrence def to_s(style=:short) case style when :short value when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Variant def to_s(style=:short) case style when :short value when :long r = " #{reifier.to_s(:short)}" if reifier i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty? "#" else super() # these () are needed, otherwise the own parameters are passed in end end end module Locator def to_s(style=:short) case style when :short value when :long value end end end RTM.register_extension( self ) end end