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.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/sequel/extensions/pg_row.rb', line 242

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