Class: PatternRuby::RegexPattern
- Inherits:
-
Object
- Object
- PatternRuby::RegexPattern
- Defined in:
- lib/pattern_ruby/intent.rb
Overview
Wraps a raw Regexp as a pattern
Instance Attribute Summary collapse
-
#entity_count ⇒ Object
readonly
Returns the value of attribute entity_count.
-
#entity_names ⇒ Object
readonly
Returns the value of attribute entity_names.
-
#literal_count ⇒ Object
readonly
Returns the value of attribute literal_count.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#token_count ⇒ Object
readonly
Returns the value of attribute token_count.
Instance Method Summary collapse
-
#initialize(regex) ⇒ RegexPattern
constructor
A new instance of RegexPattern.
- #match(input) ⇒ Object
Constructor Details
#initialize(regex) ⇒ RegexPattern
Returns a new instance of RegexPattern.
134 135 136 137 138 139 140 141 |
# File 'lib/pattern_ruby/intent.rb', line 134 def initialize(regex) @source = regex.source @regex = regex @entity_names = regex.named_captures.keys.map(&:to_sym) @literal_count = 0 @token_count = 1 @entity_count = @entity_names.size end |
Instance Attribute Details
#entity_count ⇒ Object (readonly)
Returns the value of attribute entity_count.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def entity_count @entity_count end |
#entity_names ⇒ Object (readonly)
Returns the value of attribute entity_names.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def entity_names @entity_names end |
#literal_count ⇒ Object (readonly)
Returns the value of attribute literal_count.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def literal_count @literal_count end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def regex @regex end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def source @source end |
#token_count ⇒ Object (readonly)
Returns the value of attribute token_count.
132 133 134 |
# File 'lib/pattern_ruby/intent.rb', line 132 def token_count @token_count end |
Instance Method Details
#match(input) ⇒ Object
143 144 145 |
# File 'lib/pattern_ruby/intent.rb', line 143 def match(input) @regex.match(input) end |