Class: URITemplate::RFC6570::RegexBuilder
- Inherits:
-
Object
- Object
- URITemplate::RFC6570::RegexBuilder
- Defined in:
- lib/uri_template/rfc6570/regex_builder.rb
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #capture(&block) ⇒ Object
- #character_class(max_length = 0, min = 0) ⇒ Object
- #character_class_with_comma(max_length = 0, min = 0) ⇒ Object
- #escaped_pair_connector ⇒ Object
- #escaped_prefix ⇒ Object
- #escaped_separator ⇒ Object
- #group(capture = false) ⇒ Object
-
#initialize(expression_class) ⇒ RegexBuilder
constructor
A new instance of RegexBuilder.
- #join ⇒ Object
- #length(*args) ⇒ Object
- #lookahead ⇒ Object
- #negative_lookahead ⇒ Object
- #push(*args) ⇒ Object
- #reluctant ⇒ Object
- #separated_list(first = true, length = 0, min = 1, &block) ⇒ Object
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_connector ⇒ Object
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_prefix ⇒ Object
53 54 55 |
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 53 def escaped_prefix self << Regexp.escape(@expression_class::PREFIX) end |
#escaped_separator ⇒ Object
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 |
#join ⇒ Object
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 |
#lookahead ⇒ Object
90 91 92 93 94 |
# File 'lib/uri_template/rfc6570/regex_builder.rb', line 90 def lookahead self << '(?=' yield self << ')' end |
#negative_lookahead ⇒ Object
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 |
#reluctant ⇒ Object
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 |