Class: CsvPiper::Builder

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

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



3
4
5
6
# File 'lib/csv_piper/builder.rb', line 3

def initialize
  @pre_processors = []
  @processors = []
end

Instance Method Details

#buildObject



33
34
35
36
37
38
# File 'lib/csv_piper/builder.rb', line 33

def build
  build_options = { io_stream: @io, pre_processors: @pre_processors, processors: @processors }
  build_options[:csv_options] = @csv_options if @csv_options
  build_options[:required_headers] = @required_headers if @required_headers
  Piper.new(build_options)
end

#from(io_stream) ⇒ Object



8
9
10
11
# File 'lib/csv_piper/builder.rb', line 8

def from(io_stream)
  @io = io_stream
  self
end

#requires_headers(headers) ⇒ Object



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

def requires_headers(headers)
  @required_headers = headers
  self
end

#with_csv_options(options) ⇒ Object



23
24
25
26
# File 'lib/csv_piper/builder.rb', line 23

def with_csv_options(options)
  @csv_options = options
  self
end

#with_pre_processors(pre_processors) ⇒ Object



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

def with_pre_processors(pre_processors)
  @pre_processors += pre_processors
  self
end

#with_processors(processors) ⇒ Object



18
19
20
21
# File 'lib/csv_piper/builder.rb', line 18

def with_processors(processors)
  @processors += processors
  self
end