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.
16 17 18 19 20 21 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 16 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
8 9 10 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 8 def file_set @file_set end |
#multi_value_separator ⇒ String (readonly)
separator for terms that have more than one value
8 9 10 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 8 def multi_value_separator @multi_value_separator end |
#terms ⇒ Array (readonly)
list of terms that will be output in CSV form
8 9 10 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 8 def terms @terms end |
Instance Method Details
#csv ⇒ Object
provide csv version of the GenericFile
24 25 26 27 28 29 30 31 32 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 24 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
35 36 37 38 39 |
# File 'app/services/hyrax/file_set_csv_service.rb', line 35 def csv_header ::CSV.generate do |csv| csv << terms end end |