Sha256: eb85e77f17a2c92017e2b1ec0d778e7d12e093c32c65de969d6686e1536c848e

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
# License:   Apache License, Version 2.0

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 =~ /^(=|sl:)\s*(.+)/
      return $2 if $2 
      # old: 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] # old version
      iri =~ /^(=|sl:)\s*(.+)/
    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 =~ /^(\^|ii:)\s*(.*)/
      # iri.to_s[0] == "^"[0] # old version
    end
    
    def self.is_a_sid?(iri)
      iri =~ /^(si:)\s*(.+)/
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rtm-0.3.1 lib/rtm/helpers/locator.rb
rtm-0.3.0 lib/rtm/helpers/locator.rb
rtm-0.2.1 lib/rtm/helpers/locator.rb
rtm-0.2.0 lib/rtm/helpers/locator.rb
rtm-0.2 lib/rtm/helpers/locator.rb