Module: BlacklightInternetArchive::Response
- Included in:
- HashWithResponse
- Defined in:
- lib/blacklight_internet_archive/response.rb
Defined Under Namespace
Classes: PaginatedDocSet
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/blacklight_internet_archive/response.rb', line 3 def self.included(base) unless base < Hash raise ArgumentError, "InternetArchive::Response expects to included only in (sub)classes of Hash; got included in '#{base}' instead." end base.send(:attr_reader, :request, :response) end |
Instance Method Details
#initialize_response(request, response, result) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/blacklight_internet_archive/response.rb', line 10 def initialize_response(request, response, result) @request = request @response = response self.merge!(result) if self['response'] && self['response']['docs'].is_a?(::Array) docs = PaginatedDocSet.new(self['response']['docs']) docs.per_page = request[:params]['rows'] docs.page_start = request[:params]['start'] docs.total = self['response']['numFound'].to_s.to_i self['response']['docs'] = docs end end |
#with_indifferent_access ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/blacklight_internet_archive/response.rb', line 23 def with_indifferent_access if defined?(::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse) ::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.new(request, response, self) else if defined?(ActiveSupport::HashWithIndifferentAccess) BlacklightInternetArchive.const_set('HashWithIndifferentAccessWithResponse', Class.new(ActiveSupport::HashWithIndifferentAccess)) BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.class_eval <<-eos include BlacklightInternetArchive::Response def initialize(request, response, result) super() initialize_response(request, response, result) end eos ::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.new(request, response, self) else raise RuntimeError, 'HashWithIndifferentAccess is not currently defined' end end end |