Class: Bulkrax::SampleCsvService
- Inherits:
-
Object
- Object
- Bulkrax::SampleCsvService
- Defined in:
- app/services/bulkrax/sample_csv_service.rb
Overview
Sample Usage:
Bulkrax::SampleCsvService.call(model_name: 'GenericWork', output: 'file', file_path: 'path/to/output.csv')
Bulkrax::SampleCsvService.call(model_name: nil, output: 'csv_string')
Defined Under Namespace
Classes: ColumnBuilder, ColumnDescriptor, CsvBuilder, ExplanationBuilder, FieldAnalyzer, FilePathGenerator, MappingManager, ModelLoader, RowBuilder, SchemaAnalyzer, SplitFormatter, ValueDeterminer
Instance Attribute Summary collapse
-
#all_models ⇒ Object
readonly
Returns the value of attribute all_models.
-
#field_analyzer ⇒ Object
readonly
Delegate methods to appropriate components.
-
#mapping_manager ⇒ Object
readonly
Returns the value of attribute mapping_manager.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model_name: nil) ⇒ SampleCsvService
constructor
A new instance of SampleCsvService.
- #to_csv_string ⇒ Object
- #to_file(file_path: nil) ⇒ Object
Constructor Details
#initialize(model_name: nil) ⇒ SampleCsvService
Returns a new instance of SampleCsvService.
49 50 51 52 53 54 55 56 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 49 def initialize(model_name: nil) @model_name = model_name @mapping_manager = MappingManager.new @mappings = @mapping_manager.mappings @all_models = ModelLoader.new(model_name).models @field_analyzer = FieldAnalyzer.new(@mappings) @csv_builder = CsvBuilder.new(self) end |
Instance Attribute Details
#all_models ⇒ Object (readonly)
Returns the value of attribute all_models.
47 48 49 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 47 def all_models @all_models end |
#field_analyzer ⇒ Object (readonly)
Delegate methods to appropriate components
74 75 76 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 74 def field_analyzer @field_analyzer end |
#mapping_manager ⇒ Object (readonly)
Returns the value of attribute mapping_manager.
76 77 78 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 76 def mapping_manager @mapping_manager end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
47 48 49 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 47 def mappings @mappings end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
47 48 49 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 47 def model_name @model_name end |
Class Method Details
.call(model_name: nil, output: 'file', **args) ⇒ Object
58 59 60 61 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 58 def self.call(model_name: nil, output: 'file', **args) raise NameError, "Hyrax is not defined" unless defined?(::Hyrax) new(model_name: model_name).send("to_#{output}", **args) end |
Instance Method Details
#to_csv_string ⇒ Object
69 70 71 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 69 def to_csv_string @csv_builder.generate_string end |
#to_file(file_path: nil) ⇒ Object
63 64 65 66 67 |
# File 'app/services/bulkrax/sample_csv_service.rb', line 63 def to_file(file_path: nil) file_path ||= FilePathGenerator.default_path @csv_builder.write_to_file(file_path) file_path end |