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

parse()

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

[Source]

         # File lib/sequel/extensions/pg_row.rb, line 213
    213:         def parse
    214:           return @result if @result
    215:           values = []
    216:           skip(OPEN_PAREN)
    217:           if skip(CLOSE_PAREN)
    218:             values << nil
    219:           else
    220:             until eos?
    221:               if skip(QUOTE_RE)
    222:                 values << scan(QUOTED_RE).gsub(REPLACE_RE, REPLACE_WITH)
    223:                 skip(QUOTE_SEP_RE)
    224:               else
    225:                 v = scan(UNQUOTED_RE)
    226:                 values << (v unless v.empty?)
    227:                 skip(SEP_RE)
    228:               end
    229:             end
    230:           end
    231:           values
    232:         end

[Validate]