Module: RTM::Sugar::Topic::TopicRef
- Defined in:
- lib/rtm/sugar/topic/topic_ref.rb
Instance Method Summary collapse
-
#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.
Instance Method Details
#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
71 72 73 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 71 def reference(params = {}) return references(params).sort_by{|identifier| identifier.size}.reverse.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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 28 def references(params = {}) default_hash = {:outputstyle => :ctm, :resolve_qnames => :false} params = default_hash.merge(params) if params.is_a? Hash case params[:outputstyle] when :yaml identifiers = subject_identifiers.map{|si| "si:#{si.reference}"} + subject_locators.map{ |sl| "sl:#{sl.reference}"} + item_identifiers.map{ |ii| "ii:#{ii.reference}"} when :blank identifiers = subject_identifiers.map{|si| si.reference} + subject_locators.map{ |sl| sl.reference} + item_identifiers.map{ |ii| ii.reference} else #:ctm default identifiers = subject_identifiers.map{|si| si.reference} + subject_locators.map{ |sl| "=#{sl.reference}"} + item_identifiers.map{ |ii| "^#{ii.reference}"} 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
80 81 82 |
# File 'lib/rtm/sugar/topic/topic_ref.rb', line 80 def references_as_locators subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a end |