Class: BerkeleyLibrary::TIND::Export::ExportFormat
- Inherits:
-
TypesafeEnum::Base
- Object
- TypesafeEnum::Base
- BerkeleyLibrary::TIND::Export::ExportFormat
- Defined in:
- lib/berkeley_library/tind/export/export_format.rb
Constant Summary collapse
- DEFAULT =
ODS
Class Method Summary collapse
-
.ensure_format(format) ⇒ ExportFormat
Converts a string or symbol to an ExportFormat, or returns an ExportFormat if passed on.
Instance Method Summary collapse
- #default? ⇒ Boolean
- #description ⇒ Object
- #exporter_for(collection, exportable_only: true) ⇒ Object
- #inspect ⇒ Object
- #mime_type ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
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
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
42 43 44 |
# File 'lib/berkeley_library/tind/export/export_format.rb', line 42 def default? self == DEFAULT end |
#description ⇒ Object
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 |
#inspect ⇒ Object
38 39 40 |
# File 'lib/berkeley_library/tind/export/export_format.rb', line 38 def inspect "#{ExportFormat}::#{key}" end |
#mime_type ⇒ Object
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_s ⇒ Object
29 30 31 32 |
# File 'lib/berkeley_library/tind/export/export_format.rb', line 29 def to_s # noinspection RubyYardReturnMatch value end |
#to_str ⇒ Object
34 35 36 |
# File 'lib/berkeley_library/tind/export/export_format.rb', line 34 def to_str value end |