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

Parameters:

  • collection (String)

    The collection name

  • exportable_only (Boolean) (defaults to: true)

    whether to include only exportable fields



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)

Returns the collection name.

Returns:

  • (String)

    the collection name



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

def collection
  @collection
end

#exportable_onlyBoolean (readonly)

Returns whether to include only exportable fields.

Returns:

  • (Boolean)

    whether to include only exportable fields



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

Returns:

  • (Boolean)


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

Parameters:

  • out (IO, String, Pathname, nil) (defaults to: nil)

    the IO or file path to write the exported data to, or nil to return a string

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

Returns:

Raises:

  • NoResultsError if no search results were returned for the collection



78
79
80
81
82
83
# 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

#respond_to?(*args) ⇒ Boolean


Object overrides

Returns:

  • (Boolean)


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