Class: BerkeleyLibrary::TIND::Export::ExportFormat

Inherits:
TypesafeEnum::Base
  • Object
show all
Defined in:
lib/berkeley_library/tind/export/export_format.rb

Constant Summary collapse

DEFAULT =
ODS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ensure_format(format) ⇒ ExportFormat

Converts a string or symbol to an BerkeleyLibrary::TIND::Export::ExportFormat, or returns an BerkeleyLibrary::TIND::Export::ExportFormat if passed on

Parameters:

Returns:

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
# 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

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/berkeley_library/tind/export/export_format.rb', line 42

def default?
  self == DEFAULT
end

#descriptionObject



19
20
21
22
# 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) ⇒ Object



14
15
16
17
# 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

#inspectObject



38
39
40
# File 'lib/berkeley_library/tind/export/export_format.rb', line 38

def inspect
  "#{ExportFormat}::#{key}"
end

#mime_typeObject



24
25
26
27
# 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_sObject



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

def to_s
  # noinspection RubyYardReturnMatch
  value
end

#to_strObject



34
35
36
# File 'lib/berkeley_library/tind/export/export_format.rb', line 34

def to_str
  value
end