Module: Hyrax::Ingest::Transformer

Defined in:
lib/hyrax/ingest/transformer.rb,
lib/hyrax/ingest/transformer/base.rb,
lib/hyrax/ingest/transformer/to_date.rb

Defined Under Namespace

Classes: Base, ToDate

Class Method Summary collapse

Class Method Details

.all_classesObject

Returns Set The set of all transformer classes.

Returns:

  • Set The set of all transformer classes.



9
10
11
12
13
# File 'lib/hyrax/ingest/transformer.rb', line 9

def all_classes
  @all_classes ||= Set.new.tap do |all_classes|
    all_classes << Hyrax::Ingest::Transformer::ToDate
  end
end

.factory(class_name, options = {}) ⇒ Object

Returns An instance of the transformer class.

Parameters:

  • options (Hash) (defaults to: {})

    The key is the transformer class name and the value is the hash of options to pass to the constructor of the transformer class.

Returns:

  • An instance of the transformer class.



19
20
21
# File 'lib/hyrax/ingest/transformer.rb', line 19

def factory(class_name, options={})
  find_class_by_name(class_name).new(options)
end

.find_class_by_name(class_name) ⇒ Class

Returns The appropriate transformer class.

Parameters:

  • class_name (String)

    The stringified class name, with or without namespaces.

Returns:

  • (Class)

    The appropriate transformer class.

Raises:

  • (Hyrax::Ingest::Errors::UnknownTransformerClass)

    When there is no corresponding transformer class for the given value of the ‘class_name` param.

  • (Hyrax::Ingest::Errors::UnknowntransformerClass)

    When the value of ‘class_name` param is insufficient in determining a transformer class.



31
32
33
34
35
36
37
38
# File 'lib/hyrax/ingest/transformer.rb', line 31

def find_class_by_name(class_name)
  found_classes = all_classes.select do |class_const|
    (class_const.to_s == class_name) || (class_const.to_s =~ /::#{class_name}/)
  end
  raise Hyrax::Ingest::Errors::UnknownTransformerClass.new(class_name, all_classes) if found_classes.count == 0
  raise Hyrax::Ingest::Errors::AmbiguousTransformerClass.new(class_name, found_classes) if found_classes.count > 1
  found_classes.first
end