Class: DataForge::File::CSV::CSVRecordFileDefinition

Inherits:
Object
  • Object
show all
Extended by:
DSL::Attributes
Defined in:
lib/data_forge/file/csv/csv_record_file_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL::Attributes

define_attribute

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

#fieldsObject (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

#nameObject (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_namesObject



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