Class: Embulk::Parser::XPathParserPlugin
- Inherits:
-
ParserPlugin
- Object
- ParserPlugin
- Embulk::Parser::XPathParserPlugin
- Defined in:
- lib/embulk/parser/xpath.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config) {|task, columns| ... } ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/embulk/parser/xpath.rb', line 9 def self.transaction(config, &control) schema = config.param("schema", :array) schema_serialized = schema.inject({}) do |memo, s| memo[s["name"]] = s["type"] memo end task = { :schema => schema_serialized, :root => config.param("root", :string), :namespaces => config.param("namespaces", :hash) } columns = schema.each_with_index.map do |c, i| Column.new(i, c["name"], c["type"].to_sym) end yield(task, columns) end |
Instance Method Details
#run(file_input) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/embulk/parser/xpath.rb', line 26 def run(file_input) on_new_record = lambda {|record| @page_builder.add(record) } doc = RecordBinder.new(@task["root"], @task["schema"], @task["namespaces"], on_new_record) while file = file_input.next_file data = file.read if !data.nil? && !data.empty? doc.clear doc.parse(data) end end @page_builder.finish end |