Class: CurationConcerns::PresenterFactory

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/curation_concerns/presenter_factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ids, klass, *args) ⇒ PresenterFactory

Returns a new instance of PresenterFactory.



15
16
17
18
19
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 15

def initialize(ids, klass, *args)
  @ids = ids
  @klass = klass
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



13
14
15
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 13

def args
  @args
end

#idsObject (readonly)

Returns the value of attribute ids.



13
14
15
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 13

def ids
  @ids
end

#klassObject (readonly)

Returns the value of attribute klass.



13
14
15
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 13

def klass
  @klass
end

Class Method Details

.build_presenters(ids, klass, *args) ⇒ Array

Returns presenters for the documents in order of the ids.

Parameters:

  • ids (Array)

    the list of ids to load

  • klass (Class)

    the class of presenter to make

  • args (Array)

    any other arguments to pass to the presenters

Returns:

  • (Array)

    presenters for the documents in order of the ids



8
9
10
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 8

def build_presenters(ids, klass, *args)
  new(ids, klass, *args).build
end

Instance Method Details

#buildObject



21
22
23
24
25
26
27
28
# File 'app/presenters/curation_concerns/presenter_factory.rb', line 21

def build
  return [] if ids.blank?
  docs = load_docs
  ids.map do |id|
    solr_doc = docs.find { |doc| doc.id == id }
    klass.new(solr_doc, *args) if solr_doc
  end.compact
end