Class: Sequel::Postgres::PGRow::Splitter

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/sequel/extensions/pg_row.rb

Overview

This parser-like class splits the PostgreSQL row-valued/composite type output string format into an array of strings. Note this class makes no attempt to handle all input formats that PostgreSQL will accept, it only handles the output format that PostgreSQL uses.

Instance Method Summary collapse

Instance Method Details

#parseObject

Split the stored string into an array of strings, handling the different types of quoting.


224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/sequel/extensions/pg_row.rb', line 224

def parse
  return @result if @result
  values = []
  skip(/\(/)
  if skip(/\)/)
    values << nil
  else
    until eos?
      if skip(/"/)
        values << scan(/(\\.|""|[^"])*/).gsub(/\\(.)|"(")/, '\1\2')
        skip(/"[,)]/)
      else
        v = scan(/[^,)]*/)
        values << (v unless v.empty?)
        skip(/[,)]/)
      end
    end
  end
  values
end