Class: Blacklight::JsonPresenter
- Inherits:
-
Object
- Object
- Blacklight::JsonPresenter
- Includes:
- Facet
- Defined in:
- app/presenters/blacklight/json_presenter.rb
Instance Attribute Summary collapse
-
#blacklight_config ⇒ Object
readonly
Returns the value of attribute blacklight_config.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Instance Method Summary collapse
-
#initialize(response, documents, facets, blacklight_config) ⇒ JsonPresenter
constructor
A new instance of JsonPresenter.
-
#pagination_info ⇒ Object
extract the pagination info from the response object.
- #search_facets_as_json ⇒ Object
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.
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_config ⇒ Object (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 |
#documents ⇒ Object (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_info ⇒ Object
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_json ⇒ Object
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 |