Class: DataKit::CSV::Converter
- Inherits:
-
Object
- Object
- DataKit::CSV::Converter
- Defined in:
- lib/data_kit/csv/converter.rb
Instance Attribute Summary collapse
-
#analysis ⇒ Object
Returns the value of attribute analysis.
-
#csv ⇒ Object
Returns the value of attribute csv.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
- #field_types ⇒ Object
-
#initialize(csv, analysis, output_path) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(csv, analysis, output_path) ⇒ Converter
Returns a new instance of Converter.
11 12 13 14 15 |
# File 'lib/data_kit/csv/converter.rb', line 11 def initialize(csv, analysis, output_path) @csv = csv @analysis = analysis @output_path = File.(output_path) end |
Instance Attribute Details
#analysis ⇒ Object
Returns the value of attribute analysis.
8 9 10 |
# File 'lib/data_kit/csv/converter.rb', line 8 def analysis @analysis end |
#csv ⇒ Object
Returns the value of attribute csv.
7 8 9 |
# File 'lib/data_kit/csv/converter.rb', line 7 def csv @csv end |
#output_path ⇒ Object
Returns the value of attribute output_path.
9 10 11 |
# File 'lib/data_kit/csv/converter.rb', line 9 def output_path @output_path end |
Class Method Details
.convert(csv, analysis, output_path) ⇒ Object
37 38 39 40 41 |
# File 'lib/data_kit/csv/converter.rb', line 37 def convert(csv, analysis, output_path) converter = new(csv, analysis, output_path) converter.execute converter end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/data_kit/csv/converter.rb', line 17 def execute ::CSV.open(output_path, 'wb') do |writer| first = true converted = [] csv.each_row do |row| if first first = false writer << csv.headers end writer << convert_row(csv.headers, row) end end end |
#field_types ⇒ Object
32 33 34 |
# File 'lib/data_kit/csv/converter.rb', line 32 def field_types @field_types ||= analysis.field_types end |