class BerkeleyLibrary::TIND::Export::Exporter
Superclass of exporters for different formats
Attributes
@return [String] the collection name
@return [Boolean] whether to include only exportable fields
Public Class Methods
Initializes a new exporter
@param collection [String] The collection name @param exportable_only
[Boolean] whether to include only exportable fields
# File lib/berkeley_library/tind/export/exporter.rb, line 29 def initialize(collection, exportable_only: true) @collection = collection @exportable_only = exportable_only end
Public Instance Methods
Returns true if the collection can be exported, false otherwise. Note that this requires reading the collection data from the TIND
server; failures will be fast but success may be slow. (On the other hand, the retrieved collection data is cached, so the subsequent export will not need to retrieve it again.)
# File lib/berkeley_library/tind/export/exporter.rb, line 55 def any_results? !_export_table.empty? end
Exports the collection @param out [IO, String, Pathname, nil] the IO or file path to write the
exported data to, or nil to return a string
rubocop:disable Lint/UnusedMethodArgument
# File lib/berkeley_library/tind/export/exporter.rb, line 41 def export(out = nil) # This is a stub, used for documentation raise NoMethodError, "#{self.class} does not implement `export`" end
Object overrides
# File lib/berkeley_library/tind/export/exporter.rb, line 62 def respond_to?(*args) return false if instance_of?(Exporter) && (args && args.first.to_s == 'export') super end
Protected Instance Methods
Returns a table of all records in the specified collection
@return [Export::Table] the table @raise NoResultsError
if no search results were returned for the collection
# File lib/berkeley_library/tind/export/exporter.rb, line 78 def export_table # TODO: something more clever. Search.has_results? return _export_table unless _export_table.empty? raise no_results_error end
Private Instance Methods
# File lib/berkeley_library/tind/export/exporter.rb, line 91 def _export_table @_export_table ||= begin logger.info("Reading collection #{collection.inspect}") results = API::Search.new(collection: collection).each_result(freeze: true) logger.info('Creating export table') # noinspection RubyYardParamTypeMatch Export::Table.from_records(results, freeze: true, exportable_only: exportable_only) end end
# File lib/berkeley_library/tind/export/exporter.rb, line 87 def no_results_error NoResultsError.new("No records returned for collection #{collection.inspect}") end