lib/embulk/parser/xpath.rb in embulk-parser-xml-0.0.8 vs lib/embulk/parser/xpath.rb in embulk-parser-xml-0.0.9

- old
+ new

@@ -25,11 +25,11 @@ data = file.read if !data.nil? && !data.empty? Nokogiri::XML(data).xpath(@task["root"], @task["namespaces"]).each do |item| dest = @task["schema"].inject([]) do |memo, s| es = item.xpath(s["path"], @namespaces) - memo << convert(es.empty? ? nil : es.text, s["type"]) + memo << convert(es.empty? ? nil : es.map(&:text), s["type"]) memo end @page_builder.add(dest) end end @@ -37,23 +37,27 @@ @page_builder.finish end private def convert(val, type) - v = val.nil? ? "" : val + v = if type == "json" + val.nil? ? nil : val + else + val.nil? ? "" : val.join("") + end case type - when "string" - v - when "long" - v.to_i - when "double" - v.to_f - when "boolean" - ["yes", "true", "1"].include?(v.downcase) - when "timestamp" - v.empty? ? nil : Time.strptime(v, c["format"]) - else - raise "Unsupported type '#{type}'" + when "string", "json" + v + when "long" + v.to_i + when "double" + v.to_f + when "boolean" + ["yes", "true", "1"].include?(v.downcase) + when "timestamp" + v.empty? ? nil : Time.strptime(v, c["format"]) + else + raise "Unsupported type '#{type}'" end end end end end