Module: RTM::Sugar::Topic::TopicRef
- Defined in:
- lib/rtm/sugar/topic/topic_ref.rb
Instance Method Summary collapse
-
#has_ii?(identifier) ⇒ Boolean
Returns true if this topic has an item identifer equal to the given identifier.
-
#has_si?(identifier) ⇒ Boolean
Returns true if this topic has a subject identifer equal to the given identifier.
-
#has_sl?(identifier) ⇒ Boolean
Returns true if this topic has a subject locator equal to the given identifier.
-
#has_type_with_ii?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has an item identifer equal to the given identifier.
-
#has_type_with_si?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has a subject identifer equal to the given identifier.
-
#has_type_with_sl?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has a subject locator equal to the given identifier.
-
#reference(params = {}) ⇒ Object
Returns one identifier of this topic.
-
#references(params = {}) ⇒ Object
Returns an Array including all identifiers of this Topic.
-
#references_as_locators ⇒ Object
Returns all identifiers of this Topic as Array of Locators.
-
#unresolve(identifier) ⇒ Object
Unresolves the identifier against the base_iri.
Instance Method Details
#has_ii?(identifier) ⇒ Boolean
Returns true if this topic has an item identifer equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_ii?(identifier) -> true or false
155 156 157 158 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 155 def has_ii?(identifier) identifier = topic_map.create_locator(identifier) return item_identifiers.include?(identifier) end |
#has_si?(identifier) ⇒ Boolean
Returns true if this topic has a subject identifer equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_si?(identifier) -> true or false
139 140 141 142 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 139 def has_si?(identifier) identifier = topic_map.create_locator(identifier) return subject_identifiers.include?(identifier) end |
#has_sl?(identifier) ⇒ Boolean
Returns true if this topic has a subject locator equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_sl?(identifier) -> true or false
171 172 173 174 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 171 def has_sl?(identifier) identifier = topic_map.create_locator(identifier) return subject_locators.include?(identifier) end |
#has_type_with_ii?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has an item identifer equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_type_with_ii?(identifier) -> true or false
207 208 209 210 211 212 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 207 def has_type_with_ii?(identifier) types.each do |type| return true if type.has_ii?(identifier) end return false end |
#has_type_with_si?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has a subject identifer equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_type_with_si?(identifier) -> true or false
188 189 190 191 192 193 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 188 def has_type_with_si?(identifier) types.each do |type| return true if type.has_si?(identifier) end return false end |
#has_type_with_sl?(identifier) ⇒ Boolean
Returns true if this topic is instance of another topic, that has a subject locator equal to the given identifier. Returns false otherwise.
A relative identifier is resolved against the base_iri of the topic map. QNames are resolved beforehand.
Identifier may be a String or Locator.
:call-seq:
has_type_with_sl?(identifier) -> true or false
226 227 228 229 230 231 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 226 def has_type_with_sl?(identifier) types.each do |type| return true if type.has_sl?(identifier) end return false end |
#reference(params = {}) ⇒ Object
Returns one identifier of this topic. If several exist, the shortest one is returned.
This method takes a Hash as argument.
The key :ouputstyle defines if the ctm style (value :ctm, this is the default), the YAML style (value :yaml) or no style (value :blank) is supported.
In ctm style an item identifier starts with a “^”, a subject locator starts with a “=” and a subject identifiers contains no prefix.
In yaml style an item identifiers start with a “ii:”, a subject locator starts with a “sl:” and a subject identifier start with a “si:”.
:call-seq:
reference -> String
reference(params = {}) -> String
97 98 99 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 97 def reference(params = {}) return references(params).first end |
#references(params = {}) ⇒ Object
Returns an Array including all identifiers of this Topic.
This method takes a Hash as argument.
The key :ouputstyle defines if the ctm style (value :ctm, this is the default), the YAML style (value :yaml) or no style (value :blank) is supported.
In ctm style an item identifier starts with a “^”, a subject locator starts with a “=” and a subject identifiers contains no prefix.
In yaml style an item identifiers start with a “ii:”, a subject locator starts with a “sl:” and a subject identifier start with a “si:”.
:call-seq:
references -> Array of Strings
references(params = {}) -> Array of Strings
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 27 def references(params = {}) default_hash = {:outputstyle => :ctm, :resolve_qnames => :false, :resolve_base_iri => :false, :sort_by_length => :true} params = default_hash.merge(params) if params.is_a? Hash prefixes = topic_map.prefixes set_of_si = subject_identifiers.map{|si| si.reference} set_of_sl = subject_locators.map{|si| si.reference} set_of_ii = item_identifiers.map{|si| si.reference} if params[:resolve_qnames] == :true unless prefixes.empty? prefixes.each do |identifier, reference| set_of_si = set_of_si.map{|si| si.index(reference) == 0 ? si.sub(reference, identifier + ":") : si} set_of_sl = set_of_sl.map{|sl| sl.index(reference) == 0 ? sl.sub(reference, identifier + ":") : sl} set_of_ii = set_of_ii.map{|ii| ii.index(reference) == 0 ? ii.sub(reference, identifier + ":") : ii} end end end if params[:resolve_base_iri] == :true set_of_si = set_of_si.map{|si| unresolve(si)} set_of_sl = set_of_sl.map{|sl| unresolve(sl)} set_of_ii = set_of_ii.map{|ii| unresolve(ii)} end if params[:sort_by_length] == :true set_of_si = set_of_si.sort_by{|si| si.length} set_of_sl = set_of_sl.sort_by{|sl| sl.length} set_of_ii = set_of_ii.sort_by{|ii| ii.length} end case params[:outputstyle] when :yaml, :jtm identifiers = set_of_si.map{ |si| "si:#{si}"} + set_of_sl.map{ |sl| "sl:#{sl}"} + set_of_ii.map{ |ii| "ii:#{ii}"} when :blank identifiers = set_of_si + set_of_sl + set_of_ii else #:ctm default identifiers = set_of_si + set_of_sl.map{ |sl| "=#{sl}"} + set_of_ii.map{ |ii| "^#{ii}"} end return identifiers end |
#references_as_locators ⇒ Object
Returns all identifiers of this Topic as Array of Locators.
:call-seq:
references_as_locators -> Array of Locators
106 107 108 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 106 def references_as_locators subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a end |
#unresolve(identifier) ⇒ Object
Unresolves the identifier against the base_iri.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 111 def unresolve(identifier) raise("identifier must be a String") unless identifier.is_a?(String) base_iri = topic_map.base_iri if identifier.index(base_iri) == 0 short_form = identifier.sub(base_iri, "") if topic_map.create_locator(short_form).reference == identifier return short_form end # if short_form[0] == "/" # short_form = short_form.sub("/", "") # # end else return identifier #nothing happened end end |