Class: BerkeleyLibrary::TIND::Export::Exporter

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/berkeley_library/tind/export/exporter.rb

Overview

Superclass of exporters for different formats

Direct Known Subclasses

CSVExporter, ODSExporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, exportable_only: true) ⇒ Exporter

Initializes a new exporter



29
30
31
32
# File 'lib/berkeley_library/tind/export/exporter.rb', line 29

def initialize(collection, exportable_only: true)
  @collection = collection
  @exportable_only = exportable_only
end

Instance Attribute Details

#collectionString (readonly)



17
18
19
# File 'lib/berkeley_library/tind/export/exporter.rb', line 17

def collection
  @collection
end

#exportable_onlyBoolean (readonly)



20
21
22
# File 'lib/berkeley_library/tind/export/exporter.rb', line 20

def exportable_only
  @exportable_only
end

Instance Method Details

#any_results?Boolean

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.)



55
56
57
# File 'lib/berkeley_library/tind/export/exporter.rb', line 55

def any_results?
  !_export_table.empty?
end

#export(out = nil) ⇒ Object

Exports the collection rubocop:disable Lint/UnusedMethodArgument

Raises:

  • (NoMethodError)


41
42
43
44
# 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

#export_tableExport::Table (protected)

Returns a table of all records in the specified collection

Raises:

  • NoResultsError if no search results were returned for the collection



79
80
81
82
83
84
# File 'lib/berkeley_library/tind/export/exporter.rb', line 79

def export_table
  # TODO: something more clever. Search.has_results?
  return _export_table unless _export_table.empty?

  raise no_results_error
end

#respond_to?(*args) ⇒ Boolean


Object overrides rubocop:disable Style/RedundantParentheses



62
63
64
65
66
# 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