Class: CurationConcerns::WorkShowPresenter

Inherits:
Object
  • Object
show all
Includes:
ModelProxy, PresentsAttributes
Defined in:
app/presenters/curation_concerns/work_show_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PresentsAttributes

#attribute_to_html, #display_microdata?, #microdata_type_to_html, #permission_badge, #permission_badge_class

Methods included from ModelProxy

#persisted?, #to_model, #to_partial_path

Constructor Details

#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter

Returns a new instance of WorkShowPresenter.

Parameters:

  • solr_document (SolrDocument)
  • current_ability (Ability)
  • request (ActionDispatch::Request) (defaults to: nil)

    the http request context



24
25
26
27
28
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 24

def initialize(solr_document, current_ability, request = nil)
  @solr_document = solr_document
  @current_ability = current_ability
  @request = request
end

Instance Attribute Details

#current_abilityObject

Returns the value of attribute current_ability.



5
6
7
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 5

def current_ability
  @current_ability
end

#requestObject

Returns the value of attribute request.



5
6
7
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 5

def request
  @request
end

#solr_documentObject

Returns the value of attribute solr_document.



5
6
7
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 5

def solr_document
  @solr_document
end

Instance Method Details

#collection_presentersArray<CollectionPresenter>

Returns presenters for the collections that this work is a member of.

Returns:

  • (Array<CollectionPresenter>)

    presenters for the collections that this work is a member of



81
82
83
84
85
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 81

def collection_presenters
  PresenterFactory.build_presenters(in_collection_ids,
                                    collection_presenter_class,
                                    *presenter_factory_arguments)
end

#composite_presenter_classObject



76
77
78
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 76

def composite_presenter_class
  CompositePresenterFactory.new(file_presenter_class, work_presenter_class, ordered_ids & file_set_ids)
end

#export_as_jsonldObject



95
96
97
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 95

def export_as_jsonld
  graph.dump(:jsonld, standard_prefixes: true)
end

#export_as_ntObject



91
92
93
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 91

def export_as_nt
  graph.dump(:ntriples)
end

#export_as_ttlObject



99
100
101
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 99

def export_as_ttl
  graph.dump(:ttl)
end

#file_set_presentersArray<FileSetPresenter>

Returns presenters for the orderd_members that are FileSets.

Returns:

  • (Array<FileSetPresenter>)

    presenters for the orderd_members that are FileSets



44
45
46
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 44

def file_set_presenters
  @file_set_presenters ||= member_presenters(ordered_ids & file_set_ids)
end


87
88
89
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 87

def link_name
  current_ability.can?(:read, id) ? to_s : 'File'
end

#member_presenters(ids = ordered_ids, presenter_class = composite_presenter_class) ⇒ Array<presenter_class>

Returns presenters for the ordered_members (not filtered by class).

Parameters:

  • ids (Array<String>) (defaults to: ordered_ids)

    a list of ids to build presenters for

  • presenter_class (Class) (defaults to: composite_presenter_class)

    the type of presenter to build

Returns:

  • (Array<presenter_class>)

    presenters for the ordered_members (not filtered by class)



70
71
72
73
74
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 70

def member_presenters(ids = ordered_ids, presenter_class = composite_presenter_class)
  PresenterFactory.build_presenters(ids,
                                    presenter_class,
                                    *presenter_factory_arguments)
end

#page_titleObject



30
31
32
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 30

def page_title
  title.first
end

#representative_presenterObject

Returns FileSetPresenter presenter for the representative FileSets.

Returns:

  • FileSetPresenter presenter for the representative FileSets



49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 49

def representative_presenter
  return nil if representative_id.blank?
  @representative_presenter ||=
    begin
      result = member_presenters([representative_id]).first
      if result.respond_to?(:representative_presenter)
        result.representative_presenter
      else
        result
      end
    end
end

#work_presentersArray<WorkShowPresenter>

Returns presenters for the ordered_members that are not FileSets.

Returns:

  • (Array<WorkShowPresenter>)

    presenters for the ordered_members that are not FileSets



63
64
65
# File 'app/presenters/curation_concerns/work_show_presenter.rb', line 63

def work_presenters
  @work_presenters ||= member_presenters(ordered_ids - file_set_ids, work_presenter_class)
end