Class: PatternRuby::RegexPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/pattern_ruby/intent.rb

Overview

Wraps a raw Regexp as a pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

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_countObject (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_namesObject (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_countObject (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

#regexObject (readonly)

Returns the value of attribute regex.



132
133
134
# File 'lib/pattern_ruby/intent.rb', line 132

def regex
  @regex
end

#sourceObject (readonly)

Returns the value of attribute source.



132
133
134
# File 'lib/pattern_ruby/intent.rb', line 132

def source
  @source
end

#token_countObject (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