class Sequel::Postgres::PGMultiRange::Parser

  1. lib/sequel/extensions/pg_multirange.rb
Superclass: StringScanner

Converts strings into PGMultiRange instances.

Methods

Public Class

  1. new

Public Instance

  1. parse

Public Class methods

new(source, converter)
[show source]
   # File lib/sequel/extensions/pg_multirange.rb
62 def initialize(source, converter)
63   super(source)
64   @converter = converter 
65 end

Public Instance methods

parse()

Parse the multirange type input string into a PGMultiRange value.

[show source]
   # File lib/sequel/extensions/pg_multirange.rb
68 def parse
69   raise Sequel::Error, "invalid multirange, doesn't start with {" unless get_byte == '{'
70   ranges = []
71 
72   unless scan(/\}/)
73     while true
74       raise Sequel::Error, "unfinished multirange" unless range_string = scan_until(/[\]\)]/)
75       ranges << @converter.call(range_string)
76       
77       case sep = get_byte
78       when '}'
79         break
80       when ','
81         # nothing
82       else
83         raise Sequel::Error, "invalid multirange separator: #{sep.inspect}"
84       end
85     end
86   end
87 
88   raise Sequel::Error, "invalid multirange, remaining data after }" unless eos?
89   ranges
90 end