Class: TheDude::Expression
- Inherits:
-
Object
- Object
- TheDude::Expression
- Defined in:
- lib/the_dude/expression.rb
Constant Summary collapse
- PLACEHOLDER_REGEXP =
/\s\:(\S+)/
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
- String | Regexp
-
The expression.
Instance Method Summary collapse
-
#initialize(expr) ⇒ TheDude::Expression
constructor
Creates a new Expression instance.
-
#to_regexp ⇒ Regexp
Converts the expression to a regex.
Constructor Details
#initialize(expr) ⇒ TheDude::Expression
Creates a new Expression instance
13 14 15 16 |
# File 'lib/the_dude/expression.rb', line 13 def initialize expr @expression = expr #to_regexp end |
Instance Attribute Details
#expression ⇒ Object (readonly)
- String | Regexp
-
The expression
6 7 8 |
# File 'lib/the_dude/expression.rb', line 6 def expression @expression end |
Instance Method Details
#to_regexp ⇒ Regexp
Converts the expression to a regex. If the expression is a string, it is converted to a regex that exactly matches the string. If the expression contains variable placeholders, they are substituted for the associated regexs
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/the_dude/expression.rb', line 24 def to_regexp return @regexp unless @regexp.nil? # If we have a string, escape it turn it into a regex and send it back @regexp = /^#{Regexp.quote @expression}$/ if @expression.kind_of? String @regexp ||= @expression substitute_all_variables check_for_undefined_variables return @regexp end |