class BerkeleyLibrary::TIND::Export::ExportFormat

Constants

DEFAULT

Public Class Methods

ensure_format(format) click to toggle source

Converts a string or symbol to an {ExportFormat}, or returns an {ExportFormat} if passed on

@param format [String, Symbol, ExportFormat] the format @return [ExportFormat] the format

# File lib/berkeley_library/tind/export/export_format.rb, line 53
def ensure_format(format)
  return unless format
  return format if format.is_a?(ExportFormat)

  fmt = ExportFormat.find_by_value(format.to_s.downcase)
  return fmt if fmt

  raise ArgumentError, "Unknown #{ExportFormat}: #{format.inspect}"
end

Public Instance Methods

default?() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 42
def default?
  self == DEFAULT
end
description() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 19
def description
  return 'CSV (comma-separated text)' if self == ExportFormat::CSV
  return 'LibreOffice/OpenOffice spreadsheet' if self == ExportFormat::ODS
end
exporter_for(collection, exportable_only: true) click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 14
def exporter_for(collection, exportable_only: true)
  return CSVExporter.new(collection, exportable_only: exportable_only) if self == ExportFormat::CSV
  return ODSExporter.new(collection, exportable_only: exportable_only) if self == ExportFormat::ODS
end
inspect() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 38
def inspect
  "#{ExportFormat}::#{key}"
end
mime_type() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 24
def mime_type
  return 'text/csv' if self == ExportFormat::CSV
  return 'application/vnd.oasis.opendocument.spreadsheet' if self == ExportFormat::ODS
end
to_s() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 29
def to_s
  # noinspection RubyYardReturnMatch
  value
end
to_str() click to toggle source
# File lib/berkeley_library/tind/export/export_format.rb, line 34
def to_str
  value
end