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

Returns a new instance of Builder.

Parameters:

  • prefix (String) (defaults to: 'pfx')

    the prefix to use when building identifiers



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

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

Instance Attribute Details

#prefixString

Returns the prefix to use when building identifiers.

Returns:

  • (String)

    the prefix to use when building identifiers



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.

Parameters:

  • hint (#to_s) (defaults to: nil)

    a string-able object which may be used by the builder to generate an identifier. Hints may be required by some builders, while others may ignore them to generate an identifier by other means.

Returns:

  • (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