Sha256: 4b889e165ba8bcee495e8309a9647eb39edc2851fa9011e93166498d3e3c7212

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module RTM
  # 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.
  module LocatorHelpers
    # removes "=" (and possible whitespace thereafter) from the beginning of a String or Locator if it is there
    def self.slo2iri(slo)
      slo = slo.to_s
      slo = slo[1..-1].lstrip if slo[0] == "="[0] # remove = if slo starts with it
      slo
    end

    # prepends "=" to a String or Locator if it is not already there.
    def self.iri2slo(iri)
      return "=#{iri}" if slo[0] == "="[0]
      iri
    end

    # returns true if the String or Locator given starts with "=" 
    def self.is_a_slo?(iri)
      iri.to_s[0] == "="[0]
    end

    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
    def self.iri2iid(iri)
      return "^#{iri}" if slo[0] == "="[0]
      iri
    end

    # returns true if the String or Locator given starts with "^".
    # This catches only the prefixing-style, not the local-identifier (non-absolute-iri) style
    def self.is_a_iid?(iri)
      iri.to_s[0] == "^"[0]
    end    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtm-0.1.3 lib/rtm/locator_helpers.rb
rtm-0.1.4 lib/rtm/locator_helpers.rb
rtm-0.1.5 lib/rtm/locator_helpers.rb
rtm-0.1.6 lib/rtm/locator_helpers.rb