Class: CollectionSpace::RefName

Inherits:
Object
  • Object
show all
Defined in:
lib/collectionspace/client/refname.rb

Overview

CollectionSpace RefName

There are four patterns we need to handle:

  • urn:cspace:domain:type:name(subtype)‘label’ : Top level authority/vocabulary

  • urn:cspace:domain:type:name(subtype):item:name(identifier)‘label’ : Authority/vocabulary term

  • urn:cspace:domain:type:id(identifier)‘label’ : Collectionobject

  • urn:cspace:domain:type:id(identifier) : Procedures, relations, blobs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(refname) ⇒ RefName

Returns a new instance of RefName.



17
18
19
20
21
22
23
24
25
# File 'lib/collectionspace/client/refname.rb', line 17

def initialize(refname)
  @refname = refname
  @domain = nil
  @type = nil
  @subtype = nil
  @identifier = nil
  @label = nil
  parse
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



15
16
17
# File 'lib/collectionspace/client/refname.rb', line 15

def domain
  @domain
end

#identifierObject (readonly)

Returns the value of attribute identifier.



15
16
17
# File 'lib/collectionspace/client/refname.rb', line 15

def identifier
  @identifier
end

#labelObject (readonly)

Returns the value of attribute label.



15
16
17
# File 'lib/collectionspace/client/refname.rb', line 15

def label
  @label
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



15
16
17
# File 'lib/collectionspace/client/refname.rb', line 15

def subtype
  @subtype
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/collectionspace/client/refname.rb', line 15

def type
  @type
end

Class Method Details

.parse(refname, return_class = nil) ⇒ Object

Convenience class method, so new instance of RefName does not have to be instantiated in order to parse

As of v0.13.1, return_class is added and defaults to nil for backward compatibility Eventually this default will be deprecated, and a parsed RefName object will be returned as the default.

Any new code written using this method should set the return_class parameter to :refname_obj


48
49
50
# File 'lib/collectionspace/client/refname.rb', line 48

def self.parse(refname, return_class = nil)
  (return_class == :refname_obj) ? new(refname) : new(refname).to_h
end

Instance Method Details

#parseObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/collectionspace/client/refname.rb', line 27

def parse
  scanner = StringScanner.new(@refname)
  scanner.skip("urn:cspace:")
  @domain = to_next_colon(scanner)
  @type = to_next_colon(scanner)

  case next_segment(scanner)
  when "name"
    set_subtype(scanner)
  when "id"
    set_identifier(scanner)
  end

  self
end

#to_hObject

Returns a parsed RefName object as a hash. As of v0.13.1, this is equivalent to calling RefName.parse(‘refnamevalue’, :hash) This was added to simplify the process of updating existing code that expects a hash when calling RefName.parse



55
56
57
58
59
60
61
62
63
# File 'lib/collectionspace/client/refname.rb', line 55

def to_h
  {
    domain: domain,
    type: type,
    subtype: subtype,
    identifier: identifier,
    label: label
  }
end