Class: Hyrax::FileSetCsvService
- Inherits:
-
Object
- Object
- Hyrax::FileSetCsvService
- Defined in:
- app/services/hyrax/file_set_csv_service.rb
Overview
Generates CSV from a FileSet
Instance Attribute Summary collapse
-
#file_set ⇒ FileSet
readonly
file that will be examined to generate the CSVs.
-
#multi_value_separator ⇒ String
readonly
separator for terms that have more than one value.
-
#terms ⇒ Array
readonly
list of terms that will be output in CSV form.
Instance Method Summary collapse
-
#csv ⇒ Object
provide csv version of the GenericFile.
-
#csv_header ⇒ Object
provide csv header line for a GenericFile.
-
#initialize(file, terms = nil, multi_value_separator = '|') ⇒ FileSetCsvService
constructor
A new instance of FileSetCsvService.
Constructor Details
#initialize(file, terms = nil, multi_value_separator = '|') ⇒ FileSetCsvService
Returns a new instance of FileSetCsvService.
19 20 21 22 23 24 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 19 def initialize(file, terms = nil, multi_value_separator = '|') @file_set = file @terms = terms @terms ||= [:id, :title, :depositor, :creator, :visibility, :resource_type, :license, :file_format] @multi_value_separator = multi_value_separator end |
Instance Attribute Details
#file_set ⇒ FileSet (readonly)
file that will be examined to generate the CSVs
11 12 13 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 11 def file_set @file_set end |
#multi_value_separator ⇒ String (readonly)
separator for terms that have more than one value
11 12 13 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 11 def multi_value_separator @multi_value_separator end |
#terms ⇒ Array (readonly)
list of terms that will be output in CSV form
11 12 13 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 11 def terms @terms end |
Instance Method Details
#csv ⇒ Object
provide csv version of the GenericFile
27 28 29 30 31 32 33 34 35 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 27 def csv ::CSV.generate do |csv| csv << terms.map do |term| values = file_set.send(term) values = values.respond_to?(:to_a) ? values.to_a : [values] # make sure we have an array values.join(multi_value_separator) end end end |
#csv_header ⇒ Object
provide csv header line for a GenericFile
38 39 40 41 42 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 38 def csv_header ::CSV.generate do |csv| csv << terms end end |