Class: Blacklight::JsonPresenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Facet

#facet_by_field_name, #facet_field_names, #facet_paginator, #facets_from_request

Constructor Details

#initialize(response, documents, facets, blacklight_config) ⇒ JsonPresenter

Returns a new instance of JsonPresenter.

Parameters:

  • response (Solr::Response)

    raw solr response.

  • documents (Array<SolrDocument>)

    a list of documents

  • facets (Array)

    list of facets



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

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

Instance Attribute Details

#blacklight_configObject (readonly)

Returns the value of attribute blacklight_config.



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

def blacklight_config
  @blacklight_config
end

#documentsObject (readonly)

Returns the value of attribute documents.



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

def documents
  @documents
end

Instance Method Details

#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_facets_as_jsonObject



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

def search_facets_as_json
  @facets.as_json.each do |f|
    f.delete "options"
    f["label"] = facet_configuration_for_field(f["name"]).label
    f["items"] = f["items"].as_json.each do |i|
      i['label'] ||= i['value']
    end
  end
end