class Keep::Locator

Constants

LOCATOR_REGEXP

Attributes

hash[R]

A Locator is used to parse and manipulate Keep locator strings.

Locators obey the following syntax:

locator      ::= address hint*
address      ::= digest size-hint
digest       ::= <32 hexadecimal digits>
size-hint    ::= "+" [0-9]+
hint         ::= "+" hint-type hint-content
hint-type    ::= [A-Z]
hint-content ::= [A-Za-z0-9@_-]+

Individual hints may have their own required format:

sign-hint      ::= "+A" <40 lowercase hex digits> "@" sign-timestamp
sign-timestamp ::= <8 lowercase hex digits>
hints[R]

A Locator is used to parse and manipulate Keep locator strings.

Locators obey the following syntax:

locator      ::= address hint*
address      ::= digest size-hint
digest       ::= <32 hexadecimal digits>
size-hint    ::= "+" [0-9]+
hint         ::= "+" hint-type hint-content
hint-type    ::= [A-Z]
hint-content ::= [A-Za-z0-9@_-]+

Individual hints may have their own required format:

sign-hint      ::= "+A" <40 lowercase hex digits> "@" sign-timestamp
sign-timestamp ::= <8 lowercase hex digits>
size[R]

A Locator is used to parse and manipulate Keep locator strings.

Locators obey the following syntax:

locator      ::= address hint*
address      ::= digest size-hint
digest       ::= <32 hexadecimal digits>
size-hint    ::= "+" [0-9]+
hint         ::= "+" hint-type hint-content
hint-type    ::= [A-Z]
hint-content ::= [A-Za-z0-9@_-]+

Individual hints may have their own required format:

sign-hint      ::= "+A" <40 lowercase hex digits> "@" sign-timestamp
sign-timestamp ::= <8 lowercase hex digits>

Public Class Methods

new(hasharg, sizearg, hintarg) click to toggle source
# File lib/arvados/keep.rb, line 27
def initialize(hasharg, sizearg, hintarg)
  @hash = hasharg
  @size = sizearg
  @hints = hintarg
end
parse(tok) click to toggle source

Locator.parse returns a Locator object parsed from the string tok. Returns nil if tok could not be parsed as a valid locator.

# File lib/arvados/keep.rb, line 39
def self.parse(tok)
  begin
    Locator.parse!(tok)
  rescue ArgumentError
    nil
  end
end
parse!(tok) click to toggle source

Locator.parse! returns a Locator object parsed from the string tok, raising an ArgumentError if tok cannot be parsed.

# File lib/arvados/keep.rb, line 49
def self.parse!(tok)
  if tok.nil? or tok.empty?
    raise ArgumentError.new "locator is nil or empty"
  end

  m = LOCATOR_REGEXP.match(tok)
  unless m
    raise ArgumentError.new "not a valid locator #{tok}"
  end

  tokhash, _, toksize, _, _, trailer = m[1..6]
  tokhints = []
  if trailer
    trailer.split('+').each do |hint|
      if hint =~ /^[[:upper:]][[:alnum:]@_-]*$/
        tokhints.push(hint)
      else
        raise ArgumentError.new "invalid hint #{hint}"
      end
    end
  end

  Locator.new(tokhash, toksize, tokhints)
end
valid?(tok) click to toggle source
# File lib/arvados/keep.rb, line 33
def self.valid? tok
  !!(LOCATOR_REGEXP.match tok)
end

Public Instance Methods

signature() click to toggle source

Returns the signature hint supplied with this locator, or nil if the locator was not signed.

# File lib/arvados/keep.rb, line 76
def signature
  @hints.grep(/^A/).first
end
strip_hints() click to toggle source
# File lib/arvados/keep.rb, line 85
def strip_hints
  Locator.new(@hash, @size, [])
end
strip_hints!() click to toggle source
# File lib/arvados/keep.rb, line 89
def strip_hints!
  @hints = []
  self
end
to_s() click to toggle source
# File lib/arvados/keep.rb, line 94
def to_s
  if @size
    [ @hash, @size, *@hints ].join('+')
  else
    [ @hash, *@hints ].join('+')
  end
end
without_signature() click to toggle source

Returns an unsigned Locator.

# File lib/arvados/keep.rb, line 81
def without_signature
  Locator.new(@hash, @size, @hints.reject { |o| o.start_with?("A") })
end