lib/peddler/handlers.rb in peddler-0.2.3 vs lib/peddler/handlers.rb in peddler-0.2.4

- old
+ new

@@ -13,21 +13,25 @@ end class TabDelimitedHandler # Decodes tab-delimited content into an array of OpenStruct objects. It # assumes first line contains parameter names. - def self.decode_response(res) - lines = res.split("\n") - if lines.size > 1 - params = lines[0].split("\t").collect{ |value| value.gsub(/-/, '_') } - params_size = params.size - (1..(lines.size - 1)).collect do |line_key| - values = lines[line_key].split("\t") - data = (0..(params_size - 1)).inject({}) { |memo, key| memo.merge( { params[key] => values[key] } ) } - OpenStruct.new(data) - end + def self.decode_response(res, &block) + if block_given? + res.scan(/[^\n]+/, &block) else - res + lines = res.split("\n") + if lines.size > 1 + params = lines[0].split("\t").collect{ |value| value.gsub(/-/, '_') } + params_size = params.size + (1..(lines.size - 1)).collect do |line_key| + values = lines[line_key].split("\t") + data = (0..(params_size - 1)).inject({}) { |memo, key| memo.merge( { params[key] => values[key] } ) } + OpenStruct.new(data) + end + else + res + end end end end end end \ No newline at end of file