Module: RTM::LocatorHelpers
- Defined in:
- lib/rtm/helpers/locator.rb
Overview
Some helpers for locators which could ideally mixed into String and Locator. Anyway, they are not here to not clutter up the namespace too much.
Class Method Summary collapse
- .iid2iri(slo) ⇒ Object
- .iri2iid(iri) ⇒ Object
-
.iri2slo(iri) ⇒ Object
prepends “=” to a String or Locator if it is not already there.
-
.is_a_iid?(iri) ⇒ Boolean
returns true if the String or Locator given starts with “^”.
- .is_a_sid?(iri) ⇒ Boolean
-
.is_a_slo?(iri) ⇒ Boolean
returns true if the String or Locator given starts with “=”.
-
.slo2iri(slo) ⇒ Object
removes “=” (and possible whitespace thereafter) from the beginning of a String or Locator if it is there.
Class Method Details
.iid2iri(slo) ⇒ Object
29 30 31 32 33 |
# File 'lib/rtm/helpers/locator.rb', line 29 def self.iid2iri(slo) slo = slo.to_s slo = slo[1..-1].lstrip if slo[0] == "^"[0] # remove = if slo starts with it slo end |
.iri2iid(iri) ⇒ Object
34 35 36 37 |
# File 'lib/rtm/helpers/locator.rb', line 34 def self.iri2iid(iri) return "^#{iri}" if slo[0] == "="[0] iri end |
.iri2slo(iri) ⇒ Object
prepends “=” to a String or Locator if it is not already there.
18 19 20 21 |
# File 'lib/rtm/helpers/locator.rb', line 18 def self.iri2slo(iri) return "=#{iri}" if slo[0] == "="[0] iri end |
.is_a_iid?(iri) ⇒ Boolean
returns true if the String or Locator given starts with “^”. This catches only the prefixing-style, not the local-identifier (non-absolute-iri) style
41 42 43 44 |
# File 'lib/rtm/helpers/locator.rb', line 41 def self.is_a_iid?(iri) iri =~ /^(\^|ii:)\s*(.*)/ # iri.to_s[0] == "^"[0] # old version end |
.is_a_sid?(iri) ⇒ Boolean
46 47 48 |
# File 'lib/rtm/helpers/locator.rb', line 46 def self.is_a_sid?(iri) iri =~ /^(si:)\s*(.+)/ end |
.is_a_slo?(iri) ⇒ Boolean
returns true if the String or Locator given starts with “=”
24 25 26 27 |
# File 'lib/rtm/helpers/locator.rb', line 24 def self.is_a_slo?(iri) # iri.to_s[0] == "="[0] # old version iri =~ /^(=|sl:)\s*(.+)/ end |
.slo2iri(slo) ⇒ Object
removes “=” (and possible whitespace thereafter) from the beginning of a String or Locator if it is there
9 10 11 12 13 14 15 |
# File 'lib/rtm/helpers/locator.rb', line 9 def self.slo2iri(slo) slo = slo.to_s slo =~ /^(=|sl:)\s*(.+)/ return $2 if $2 # old: slo[1..-1].lstrip if slo[0] == "="[0] # remove = if slo starts with it slo end |