Class: Sequel::Postgres::PGRow::Splitter
- 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.
Constant Summary collapse
- 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
Instance Method Summary collapse
-
#parse ⇒ Object
Split the stored string into an array of strings, handling the different types of quoting.
Instance Method Details
#parse ⇒ Object
Split the stored string into an array of strings, handling the different types of quoting.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/sequel/extensions/pg_row.rb', line 249 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 |