Class: Embulk::Filter::ExpandCsvArray
- Inherits:
-
FilterPlugin
- Object
- FilterPlugin
- Embulk::Filter::ExpandCsvArray
- Defined in:
- lib/embulk/filter/expand_csv_array.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config, in_schema) {|task, out_columns| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/embulk/filter/expand_csv_array.rb', line 8 def self.transaction(config, in_schema, &control) # configuration code: task = { "csv_column_name" => config.param("csv_column_name", :string), "column_names" => config.param("column_names", :array, default: []) } task["target"] = in_schema.find {|c| c.name == task['csv_column_name']} task["columns"] = in_schema.select {|c| task["column_names"].include?(c.name) } out_columns = in_schema.select do |col| col if task["column_names"].find { |n| n == col.name } end yield(task, out_columns) end |
Instance Method Details
#add(page) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/embulk/filter/expand_csv_array.rb', line 35 def add(page) # filtering code: page.each do |record| record[@target["index"]].parse_csv.each do |val| data = @columns.map do |f| if f["index"] == @target["index"] val else record[f["index"]] end end page_builder.add(data) end end end |
#close ⇒ Object
32 33 |
# File 'lib/embulk/filter/expand_csv_array.rb', line 32 def close end |
#finish ⇒ Object
51 52 53 |
# File 'lib/embulk/filter/expand_csv_array.rb', line 51 def finish page_builder.finish end |
#init ⇒ Object
25 26 27 28 29 30 |
# File 'lib/embulk/filter/expand_csv_array.rb', line 25 def init # initialization code: @csv_column_name = task["csv_column_name"] @columns = task["columns"] @target = task["target"] end |