Class: EasyCSV::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/easycsv/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



12
13
14
15
16
# File 'lib/easycsv/builder.rb', line 12

def initialize
  @data = Data.new
  @wrapper = DoubleQuoteWrapper
  @separator = ComaSeparator
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



33
34
35
# File 'lib/easycsv/builder.rb', line 33

def method_missing(m, *args, &block)
  @data.send(m, *args, &block)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/easycsv/builder.rb', line 5

def data
  @data
end

#file_pathObject

Returns the value of attribute file_path.



5
6
7
# File 'lib/easycsv/builder.rb', line 5

def file_path
  @file_path
end

#separatorObject

Returns the value of attribute separator.



5
6
7
# File 'lib/easycsv/builder.rb', line 5

def separator
  @separator
end

#wrapperObject

Returns the value of attribute wrapper.



5
6
7
# File 'lib/easycsv/builder.rb', line 5

def wrapper
  @wrapper
end

Class Method Details

.build(&block) ⇒ Object



6
7
8
9
10
# File 'lib/easycsv/builder.rb', line 6

def self.build(&block)
  builder = new
  builder.instance_eval(&block)
  builder.build
end

Instance Method Details

#buildObject



18
19
20
21
22
23
# File 'lib/easycsv/builder.rb', line 18

def build
  File.open(@file_path, "w") do |f|
    f.write header_row
    f.write data_rows
  end
end

#set_column_separator(separator) ⇒ Object



25
26
27
# File 'lib/easycsv/builder.rb', line 25

def set_column_separator(separator)
  @separator = separator
end

#set_path(path) ⇒ Object



29
30
31
# File 'lib/easycsv/builder.rb', line 29

def set_path(path)
  @file_path = path
end