Module: RTM::LocatorHelpers

Defined in:
rtm/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

Class Method Details

+ (Object) iid2iri(slo)



29
30
31
32
33
# File 'rtm/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

+ (Object) iri2iid(iri)



34
35
36
37
# File 'rtm/lib/rtm/helpers/locator.rb', line 34

def self.iri2iid(iri)
  return "^#{iri}" if slo[0] == "="[0]
  iri
end

+ (Object) iri2slo(iri)

prepends “=” to a String or Locator if it is not already there.



18
19
20
21
# File 'rtm/lib/rtm/helpers/locator.rb', line 18

def self.iri2slo(iri)
  return "=#{iri}" if slo[0] == "="[0]
  iri
end

+ (Boolean) is_a_iid?(iri)

returns true if the String or Locator given starts with “^”. This catches only the prefixing-style, not the local-identifier (non-absolute-iri) style

Returns:

  • (Boolean)


41
42
43
44
# File 'rtm/lib/rtm/helpers/locator.rb', line 41

def self.is_a_iid?(iri)
  iri =~ /^(\^|ii:)\s*(.*)/
  # iri.to_s[0] == "^"[0] # old version
end

+ (Boolean) is_a_sid?(iri)

Returns:

  • (Boolean)


46
47
48
# File 'rtm/lib/rtm/helpers/locator.rb', line 46

def self.is_a_sid?(iri)
  iri =~ /^(si:)\s*(.+)/
end

+ (Boolean) is_a_slo?(iri)

returns true if the String or Locator given starts with “=“

Returns:

  • (Boolean)


24
25
26
27
# File 'rtm/lib/rtm/helpers/locator.rb', line 24

def self.is_a_slo?(iri)
  # iri.to_s[0] == "="[0] # old version
  iri =~ /^(=|sl:)\s*(.+)/
end

+ (Object) slo2iri(slo)

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 'rtm/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