class URITemplate::RFC6570::RegexBuilder

Public Class Methods

new(expression_class) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 29
def initialize(expression_class)
  @expression_class = expression_class
  @source = []
end

Public Instance Methods

<<(arg) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 34
def <<(arg)
  @source << arg
  self
end
capture(&block) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 95
def capture(&block)
  group(true, &block)
end
character_class(max_length=0, min = 0) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 68
def character_class(max_length=0, min = 0)
  self << @expression_class::CHARACTER_CLASS[:class] << format_length(max_length, min)
end
character_class_with_comma(max_length=0, min = 0) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 64
def character_class_with_comma(max_length=0, min = 0)
  self << @expression_class::CHARACTER_CLASS[:class_with_comma] << format_length(max_length, min)
end
escaped_pair_connector() click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 44
def escaped_pair_connector
  self << Regexp.escape(@expression_class::PAIR_CONNECTOR)
end
escaped_prefix() click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 52
def escaped_prefix
  self << Regexp.escape(@expression_class::PREFIX)
end
escaped_separator() click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 48
def escaped_separator
  self << Regexp.escape(@expression_class::SEPARATOR)
end
group(capture = false) { || ... } click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 76
def group(capture = false)
  self << '('
  self << '?:' unless capture
  yield
  self << ')'
end
join() click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 56
def join
  return @source.join
end
length(*args) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 60
def length(*args)
  self << format_length(*args)
end
lookahead() { || ... } click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 89
def lookahead
  self << '(?='
  yield
  self << ')'
end
negative_lookahead() { || ... } click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 83
def negative_lookahead
  self << '(?!'
  yield
  self << ')'
end
push(*args) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 39
def push(*args)
  @source.push(*args)
  self
end
reluctant() click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 72
def reluctant
  self << '?'
end
separated_list(first = true, length = 0, min = 1) { || ... } click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 99
def separated_list(first = true, length = 0, min = 1, &block)
  if first
    yield
    min -= 1
  end
  self.push('(?:').escaped_separator
  yield
  self.push(')').length(length, min)
end

Private Instance Methods

format_length(len, min = 0) click to toggle source
# File lib/uri_template/rfc6570/regex_builder.rb, line 111
def format_length(len, min = 0)
  return len if len.kind_of? String
  return '{'+min.to_s+','+len.to_s+'}' if len.kind_of?(Numeric) and len > 0
  return '*' if min == 0
  return '+' if min == 1
  return '{'+min.to_s+',}'
end