Class: DataForge::File::CSV::CSVRecordFileDefinition
- Inherits:
-
Object
- Object
- DataForge::File::CSV::CSVRecordFileDefinition
- Extended by:
- DSL::Attributes
- Defined in:
- lib/data_forge/file/csv/csv_record_file_definition.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #copy(definition) ⇒ Object
- #field(name, type = String) ⇒ Object
- #field_names ⇒ Object
-
#initialize(name) ⇒ CSVRecordFileDefinition
constructor
A new instance of CSVRecordFileDefinition.
- #without_field(name) ⇒ Object
Methods included from DSL::Attributes
Constructor Details
#initialize(name) ⇒ CSVRecordFileDefinition
Returns a new instance of CSVRecordFileDefinition.
21 22 23 24 25 26 27 28 29 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 21 def initialize(name) @name = name @file_name = "#{name.to_s}.csv" @fields = {} @delimiter = "," @quote = '"' @encoding = "UTF-8" @has_header_row = true end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
10 11 12 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 10 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 10 def name @name end |
Instance Method Details
#copy(definition) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 51 def copy(definition) delimiter definition.delimiter quote definition.quote encoding definition.encoding has_header_row definition.has_header_row definition.fields.each { |name, type| field name, type } end |
#field(name, type = String) ⇒ Object
33 34 35 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 33 def field(name, type = String) @fields[name] = type end |
#field_names ⇒ Object
45 46 47 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 45 def field_names @fields.keys end |
#without_field(name) ⇒ Object
39 40 41 |
# File 'lib/data_forge/file/csv/csv_record_file_definition.rb', line 39 def without_field(name) @fields.delete name end |