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 107 107: def parse 108: return @result if @result 109: hash = {} 110: while !eos? 111: skip(QUOTE_RE) 112: k = parse_quoted 113: skip(KV_SEP_RE) 114: if skip(QUOTE_RE) 115: v = parse_quoted 116: skip(QUOTE_RE) 117: else 118: scan(NULL_RE) 119: v = nil 120: end 121: skip(SEP_RE) 122: hash[k] = v 123: end 124: @result = hash 125: end