Class: Sequel::Postgres::PGMultiRange::Parser
- Defined in:
- lib/sequel/extensions/pg_multirange.rb
Overview
Converts strings into PGMultiRange instances.
Instance Method Summary collapse
-
#initialize(source, converter) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
Parse the multirange type input string into a PGMultiRange value.
Constructor Details
#initialize(source, converter) ⇒ Parser
Returns a new instance of Parser.
62 63 64 65 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 62 def initialize(source, converter) super(source) @converter = converter end |
Instance Method Details
#parse ⇒ Object
Parse the multirange type input string into a PGMultiRange value.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 68 def parse raise Sequel::Error, "invalid multirange, doesn't start with {" unless get_byte == '{' ranges = [] unless scan(/\}/) while true raise Sequel::Error, "unfinished multirange" unless range_string = scan_until(/[\]\)]/) ranges << @converter.call(range_string) case sep = get_byte when '}' break when ',' # nothing else raise Sequel::Error, "invalid multirange separator: #{sep.inspect}" end end end raise Sequel::Error, "invalid multirange, remaining data after }" unless eos? ranges end |