class Sequel::Postgres::PGMultiRange::Parser

Converts strings into PGMultiRange instances.

Public Class Methods

new(source, converter) click to toggle source
Calls superclass method
# File lib/sequel/extensions/pg_multirange.rb, line 61
def initialize(source, converter)
  super(source)
  @converter = converter 
end

Public Instance Methods

parse() click to toggle source

Parse the multirange type input string into a PGMultiRange value.

# File lib/sequel/extensions/pg_multirange.rb, line 67
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