Class Sequel::Postgres::PGRow::Splitter
In: lib/sequel/extensions/pg_row.rb
Parent: StringScanner

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.

Methods

parse  

Constants

OPEN_PAREN = /\(/.freeze
CLOSE_PAREN = /\)/.freeze
UNQUOTED_RE = /[^,)]*/.freeze
SEP_RE = /[,)]/.freeze
QUOTE_RE = /"/.freeze
QUOTE_SEP_RE = /"[,)]/.freeze
QUOTED_RE = /(\\.|""|[^"])*/.freeze
REPLACE_RE = /\\(.)|"(")/.freeze
REPLACE_WITH = '\1\2'.freeze

Public Instance methods

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

[Source]

     # File lib/sequel/extensions/pg_row.rb, line 232
232:         def parse
233:           return @result if @result
234:           values = []
235:           skip(OPEN_PAREN)
236:           if skip(CLOSE_PAREN)
237:             values << nil
238:           else
239:             until eos?
240:               if skip(QUOTE_RE)
241:                 values << scan(QUOTED_RE).gsub(REPLACE_RE, REPLACE_WITH)
242:                 skip(QUOTE_SEP_RE)
243:               else
244:                 v = scan(UNQUOTED_RE)
245:                 values << (v unless v.empty?)
246:                 skip(SEP_RE)
247:               end
248:             end
249:           end
250:           values
251:         end

[Validate]