Class: Keep::Locator
- Inherits:
-
Object
- Object
- Keep::Locator
- Defined in:
- lib/arvados/keep.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
A Locator is used to parse and manipulate Keep locator strings.
-
#hints ⇒ Object
readonly
A Locator is used to parse and manipulate Keep locator strings.
-
#size ⇒ Object
readonly
A Locator is used to parse and manipulate Keep locator strings.
Class Method Summary collapse
-
.parse(tok) ⇒ Object
Locator.parse returns a Locator object parsed from the string tok.
-
.parse!(tok) ⇒ Object
Locator.parse! returns a Locator object parsed from the string tok, raising an ArgumentError if tok cannot be parsed.
Instance Method Summary collapse
-
#initialize(hasharg, sizearg, hintarg) ⇒ Locator
constructor
A new instance of Locator.
-
#signature ⇒ Object
Returns the signature hint supplied with this locator, or nil if the locator was not signed.
- #strip_hints ⇒ Object
- #strip_hints! ⇒ Object
- #to_s ⇒ Object
-
#without_signature ⇒ Object
Returns an unsigned Locator.
Constructor Details
#initialize(hasharg, sizearg, hintarg) ⇒ Locator
Returns a new instance of Locator.
21 22 23 24 25 |
# File 'lib/arvados/keep.rb', line 21 def initialize(hasharg, sizearg, hintarg) @hash = hasharg @size = sizearg @hints = hintarg end |
Instance Attribute Details
#hash ⇒ Object (readonly)
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>
19 20 21 |
# File 'lib/arvados/keep.rb', line 19 def hash @hash end |
#hints ⇒ Object (readonly)
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>
19 20 21 |
# File 'lib/arvados/keep.rb', line 19 def hints @hints end |
#size ⇒ Object (readonly)
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>
19 20 21 |
# File 'lib/arvados/keep.rb', line 19 def size @size end |
Class Method Details
.parse(tok) ⇒ Object
Locator.parse returns a Locator object parsed from the string tok. Returns nil if tok could not be parsed as a valid locator.
29 30 31 32 33 34 35 |
# File 'lib/arvados/keep.rb', line 29 def self.parse(tok) begin Locator.parse!(tok) rescue ArgumentError => e nil end end |
.parse!(tok) ⇒ Object
Locator.parse! returns a Locator object parsed from the string tok, raising an ArgumentError if tok cannot be parsed.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/arvados/keep.rb', line 39 def self.parse!(tok) if tok.nil? or tok.empty? raise ArgumentError.new "locator is nil or empty" end m = /^([[:xdigit:]]{32})(\+([[:digit:]]+))?(\+([[:upper:]][[:alnum:]+@_-]*))?$/.match(tok.strip) unless m raise ArgumentError.new "not a valid locator #{tok}" end tokhash, _, toksize, _, trailer = m[1..5] tokhints = [] if trailer trailer.split('+').each do |hint| if hint =~ /^[[:upper:]][[:alnum:]@_-]+$/ tokhints.push(hint) else raise ArgumentError.new "unknown hint #{hint}" end end end Locator.new(tokhash, toksize, tokhints) end |
Instance Method Details
#signature ⇒ Object
Returns the signature hint supplied with this locator, or nil if the locator was not signed.
66 67 68 |
# File 'lib/arvados/keep.rb', line 66 def signature @hints.grep(/^A/).first end |
#strip_hints ⇒ Object
75 76 77 |
# File 'lib/arvados/keep.rb', line 75 def strip_hints Locator.new(@hash, @size, []) end |
#strip_hints! ⇒ Object
79 80 81 82 |
# File 'lib/arvados/keep.rb', line 79 def strip_hints! @hints = [] self end |
#to_s ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/arvados/keep.rb', line 84 def to_s if @size [ @hash, @size, *@hints ].join('+') else [ @hash, *@hints ].join('+') end end |