Class: Hyrax::Identifier::Builder

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/identifier/builder.rb

Overview

Builds an identifier string.

Implementations must accept a ‘prefix:` to `#initialize`, and a `hint:` to `#build`. Either or both may be used at the preference of the specific implementer or ignored entirely when `#build` is called.

Examples:

builder = Hyrax::Identifier::Builder.new(prefix: 'moomin')
builder.build(hint: '1') # => "moomin/1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix: 'pfx') ⇒ Builder



22
23
24
# File 'app/services/hyrax/identifier/builder.rb', line 22

def initialize(prefix: 'pfx')
  @prefix = prefix
end

Instance Attribute Details

#prefixString



18
19
20
# File 'app/services/hyrax/identifier/builder.rb', line 18

def prefix
  @prefix
end

Instance Method Details

#build(hint: nil) ⇒ String

Note:

this default builder requires a ‘hint` which it appends to the prefix to generate the identifier string.

Raises:

  • (ArgumentError)

    if an identifer can’t be built from the provided hint.



37
38
39
40
41
42
# File 'app/services/hyrax/identifier/builder.rb', line 37

def build(hint: nil)
  raise(ArgumentError, "No hint provided to #{self.class}#build") if
    hint.nil?

  "#{prefix}/#{hint}"
end