Class: Blacklight::JsonPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/blacklight/json_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, blacklight_config) ⇒ JsonPresenter

Returns a new instance of JsonPresenter.

Parameters:



7
8
9
10
# File 'app/presenters/blacklight/json_presenter.rb', line 7

def initialize(response, blacklight_config)
  @response = response
  @blacklight_config = blacklight_config
end

Instance Attribute Details

#blacklight_configObject (readonly)

Returns the value of attribute blacklight_config.



12
13
14
# File 'app/presenters/blacklight/json_presenter.rb', line 12

def blacklight_config
  @blacklight_config
end

Instance Method Details

#documentsObject



16
17
18
# File 'app/presenters/blacklight/json_presenter.rb', line 16

def documents
  @response.documents
end

#pagination_infoObject

extract the pagination info from the response object



29
30
31
32
33
34
35
36
37
38
39
# File 'app/presenters/blacklight/json_presenter.rb', line 29

def pagination_info
  h = {}

  [:current_page, :next_page, :prev_page, :total_pages,
   :limit_value, :offset_value, :total_count,
   :first_page?, :last_page?].each do |k|
    h[k] = @response.send(k)
  end

  h
end

#search_facetsArray<Blacklight::Solr::Response::Facets::FacetField>



21
22
23
24
25
26
# File 'app/presenters/blacklight/json_presenter.rb', line 21

def search_facets
  facet_field_names
    .map { |field| @response.aggregations[facet_configuration_for_field(field).field] }
    .compact
    .select { |display_facet| display_facet.items.present? }
end