Class | Sequel::Postgres::HStore::Parser |
In: |
lib/sequel/extensions/pg_hstore.rb
|
Parent: | StringScanner |
QUOTE_RE | = | /"/.freeze |
KV_SEP_RE | = | /"\s*=>\s*/.freeze |
NULL_RE | = | /NULL/.freeze |
SEP_RE | = | /,\s*/.freeze |
QUOTED_RE | = | /(\\"|[^"])*/.freeze |
REPLACE_RE | = | /\\(.)/.freeze |
REPLACE_WITH | = | '\1'.freeze |
Parse the output format that PostgreSQL uses for hstore columns. Note that this does not attempt to parse all input formats that PostgreSQL will accept. For instance, it expects all keys and non-NULL values to be quoted.
Return the resulting hash of objects. This can be called multiple times, it will cache the parsed hash on the first call and use it for subsequent calls.
# File lib/sequel/extensions/pg_hstore.rb, line 113 113: def parse 114: return @result if @result 115: hash = {} 116: while !eos? 117: skip(QUOTE_RE) 118: k = parse_quoted 119: skip(KV_SEP_RE) 120: if skip(QUOTE_RE) 121: v = parse_quoted 122: skip(QUOTE_RE) 123: else 124: scan(NULL_RE) 125: v = nil 126: end 127: skip(SEP_RE) 128: hash[k] = v 129: end 130: @result = hash 131: end