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

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
# File 'lib/berkeley_library/tind/export/export_format.rb', line 56

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



45
46
47
# File 'lib/berkeley_library/tind/export/export_format.rb', line 45

def default?
  self == DEFAULT
end

#descriptionObject



20
21
22
23
24
# File 'lib/berkeley_library/tind/export/export_format.rb', line 20

def description
  return 'CSV (comma-separated text)' if self == ExportFormat::CSV

  'LibreOffice/OpenOffice spreadsheet' if self == ExportFormat::ODS
end

#exporter_for(collection, exportable_only: true) ⇒ Object



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

  ODSExporter.new(collection, exportable_only: exportable_only) if self == ExportFormat::ODS
end

#inspectObject



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

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

#mime_typeObject



26
27
28
29
30
# File 'lib/berkeley_library/tind/export/export_format.rb', line 26

def mime_type
  return 'text/csv' if self == ExportFormat::CSV

  'application/vnd.oasis.opendocument.spreadsheet' if self == ExportFormat::ODS
end

#to_sObject



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

def to_s
  # noinspection RubyYardReturnMatch
  value
end

#to_strObject



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

def to_str
  value
end