Class: Hyrax::CollectionPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, ModelProxy, PresentsAttributes
Defined in:
app/presenters/hyrax/collection_presenter.rb

Direct Known Subclasses

AdminSetPresenter

Instance Attribute Summary collapse

Class Method 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) ⇒ CollectionPresenter

Returns a new instance of CollectionPresenter.

Parameters:

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

    the http request context



11
12
13
14
15
# File 'app/presenters/hyrax/collection_presenter.rb', line 11

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.



6
7
8
# File 'app/presenters/hyrax/collection_presenter.rb', line 6

def current_ability
  @current_ability
end

#requestObject

Returns the value of attribute request.



6
7
8
# File 'app/presenters/hyrax/collection_presenter.rb', line 6

def request
  @request
end

#solr_documentObject

Returns the value of attribute solr_document.



6
7
8
# File 'app/presenters/hyrax/collection_presenter.rb', line 6

def solr_document
  @solr_document
end

Class Method Details

.termsObject

Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb



29
30
31
32
33
# File 'app/presenters/hyrax/collection_presenter.rb', line 29

def self.terms
  [:total_items, :size, :resource_type, :creator, :contributor, :keyword,
   :license, :publisher, :date_created, :subject, :language, :identifier,
   :based_near, :related_url]
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'app/presenters/hyrax/collection_presenter.rb', line 39

def [](key)
  case key
  when :size
    size
  when :total_items
    total_items
  else
    solr_document.send key
  end
end

#sizeObject



50
51
52
# File 'app/presenters/hyrax/collection_presenter.rb', line 50

def size
  number_to_human_size(@solr_document['bytes_lts'])
end

#terms_with_valuesObject



35
36
37
# File 'app/presenters/hyrax/collection_presenter.rb', line 35

def terms_with_values
  self.class.terms.select { |t| self[t].present? }
end

#total_itemsObject



54
55
56
# File 'app/presenters/hyrax/collection_presenter.rb', line 54

def total_items
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").count
end