Class: EasyCSV::Builder
- Inherits:
-
Object
- Object
- EasyCSV::Builder
- Defined in:
- lib/easycsv/builder.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#separator ⇒ Object
Returns the value of attribute separator.
-
#wrapper ⇒ Object
Returns the value of attribute wrapper.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #method_missing(m, *args, &block) ⇒ Object
- #set_column_separator(separator) ⇒ Object
- #set_path(path) ⇒ Object
Constructor Details
#initialize ⇒ Builder
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
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/easycsv/builder.rb', line 5 def data @data end |
#file_path ⇒ Object
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/easycsv/builder.rb', line 5 def file_path @file_path end |
#separator ⇒ Object
Returns the value of attribute separator.
5 6 7 |
# File 'lib/easycsv/builder.rb', line 5 def separator @separator end |
#wrapper ⇒ Object
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
#build ⇒ Object
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 |