Class: URITemplate::RFC6570::RegexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/uri_template/rfc6570/regex_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(expression_class) ⇒ RegexBuilder

Returns a new instance of RegexBuilder.



30
31
32
33
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 30

def initialize(expression_class)
  @expression_class = expression_class
  @source = []
end

Instance Method Details

#<<(arg) ⇒ Object



35
36
37
38
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 35

def <<(arg)
  @source << arg
  self
end

#capture(&block) ⇒ Object



96
97
98
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 96

def capture(&block)
  group(true, &block)
end

#character_class(max_length = 0, min = 0) ⇒ Object



69
70
71
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 69

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) ⇒ Object



65
66
67
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 65

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_connectorObject



45
46
47
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 45

def escaped_pair_connector
  self << Regexp.escape(@expression_class::PAIR_CONNECTOR)
end

#escaped_prefixObject



53
54
55
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 53

def escaped_prefix
  self << Regexp.escape(@expression_class::PREFIX)
end

#escaped_separatorObject



49
50
51
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 49

def escaped_separator
  self << Regexp.escape(@expression_class::SEPARATOR)
end

#group(capture = false) ⇒ Object



77
78
79
80
81
82
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 77

def group(capture = false)
  self << '('
  self << '?:' unless capture
  yield
  self << ')'
end

#joinObject



57
58
59
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 57

def join
  return @source.join
end

#length(*args) ⇒ Object



61
62
63
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 61

def length(*args)
  self << format_length(*args)
end

#lookaheadObject



90
91
92
93
94
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 90

def lookahead
  self << '(?='
  yield
  self << ')'
end

#negative_lookaheadObject



84
85
86
87
88
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 84

def negative_lookahead
  self << '(?!'
  yield
  self << ')'
end

#push(*args) ⇒ Object



40
41
42
43
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 40

def push(*args)
  @source.push(*args)
  self
end

#reluctantObject



73
74
75
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 73

def reluctant
  self << '?'
end

#separated_list(first = true, length = 0, min = 1, &block) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 100

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