Class: Embulk::Parser::Fixed
- Inherits:
-
ParserPlugin
- Object
- ParserPlugin
- Embulk::Parser::Fixed
- Defined in:
- lib/embulk/parser/fixed.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config) {|task, columns| ... } ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/embulk/parser/fixed.rb', line 7 def self.transaction(config, &control) decoder_task = config.load_config(Java::LineDecoder::DecoderTask) # configuration code: task = { "decoder" => DataSource.from_java(decoder_task.dump), "schema" => config.param("columns", :array, default: []), "strip_whitespace" => config.param("strip_whitespace", :bool, default: true) } columns = [] task["schema"].each do |column| name = column["name"] type = column["type"].to_sym columns << Column.new(nil, name, type) end yield(task, columns) end |
Instance Method Details
#init ⇒ Object
27 28 29 30 31 |
# File 'lib/embulk/parser/fixed.rb', line 27 def init @decoder = task.param("decoder", :hash).load_task(Java::LineDecoder::DecoderTask) @schema = @task["schema"] @strip_whitespace = task["strip_whitespace"] end |
#run(file_input) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/embulk/parser/fixed.rb', line 34 def run(file_input) decoder = Java::LineDecoder.new(file_input.to_java, @decoder) while decoder.nextFile while line = decoder.poll process_line(line) end end page_builder.finish end |