Class: BerkeleyLibrary::TIND::API::Search
- Inherits:
-
Object
- Object
- BerkeleyLibrary::TIND::API::Search
- Includes:
- Logging
- Defined in:
- lib/berkeley_library/tind/api/search.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#date_range ⇒ Object
readonly
Returns the value of attribute date_range.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#each_result(freeze: false, &block) ⇒ Object
Iterates over the records returned by this search.
-
#initialize(collection: nil, pattern: nil, index: nil, date_range: nil, format: Format::XML) ⇒ Search
constructor
A new instance of Search.
-
#params ⇒ Object
rubocop: disable Metrics/AbcSize.
-
#results ⇒ Array<MARC::Record>
Performs this search and returns the results as array.
Constructor Details
#initialize(collection: nil, pattern: nil, index: nil, date_range: nil, format: Format::XML) ⇒ Search
Returns a new instance of Search.
14 15 16 17 18 19 20 21 22 |
# File 'lib/berkeley_library/tind/api/search.rb', line 14 def initialize(collection: nil, pattern: nil, index: nil, date_range: nil, format: Format::XML) raise ArgumentError, 'Search requires a collection' unless collection @collection = collection @pattern = pattern @index = index @date_range = DateRange.ensure_date_range(date_range) @format = Format.ensure_format(format) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
12 13 14 |
# File 'lib/berkeley_library/tind/api/search.rb', line 12 def collection @collection end |
#date_range ⇒ Object (readonly)
Returns the value of attribute date_range.
12 13 14 |
# File 'lib/berkeley_library/tind/api/search.rb', line 12 def date_range @date_range end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/berkeley_library/tind/api/search.rb', line 12 def format @format end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
12 13 14 |
# File 'lib/berkeley_library/tind/api/search.rb', line 12 def index @index end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
12 13 14 |
# File 'lib/berkeley_library/tind/api/search.rb', line 12 def pattern @pattern end |
Instance Method Details
#each_result(freeze: false) {|marc_record| ... } ⇒ self #each_result(freeze: false) ⇒ Enumerable<MARC::Record>
Iterates over the records returned by this search.
52 53 54 55 56 57 |
# File 'lib/berkeley_library/tind/api/search.rb', line 52 def each_result(freeze: false, &block) return to_enum(:each_result, freeze: freeze) unless block_given? perform_search(freeze: freeze, &block) self end |
#params ⇒ Object
rubocop: disable Metrics/AbcSize
25 26 27 28 29 30 31 32 33 |
# File 'lib/berkeley_library/tind/api/search.rb', line 25 def params @params ||= {}.tap do |params| params[:c] = collection if collection params[:p] = pattern if pattern params[:f] = index if index params.merge!(date_range.to_params) if date_range params[:format] = self.format.to_s if self.format end end |
#results ⇒ Array<MARC::Record>
Performs this search and returns the results as array.
38 39 40 |
# File 'lib/berkeley_library/tind/api/search.rb', line 38 def results each_result.to_a end |