Class: Excise::Base
- Inherits:
-
Object
- Object
- Excise::Base
- Defined in:
- lib/excise/base.rb
Constant Summary collapse
- TOKEN_EXPRESSION =
/{([^{}\t\r\n]+)}/.freeze
- SPECIAL_CHARACTERS_EXPRESSION =
/[\\\^\$\*\+\.\?\(\)\[\]]/.freeze
Instance Attribute Summary collapse
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(pattern, string = "") ⇒ Base
constructor
A new instance of Base.
- #parse ⇒ Object
- #parse_string(string) ⇒ Object
- #pattern_expression ⇒ Object
- #special_characters_expression ⇒ Object
- #token_expression ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(pattern, string = "") ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 |
# File 'lib/excise/base.rb', line 10 def initialize(pattern, string = "") @pattern = pattern @string = string @output = {} end |
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
8 9 10 |
# File 'lib/excise/base.rb', line 8 def string @string end |
Instance Method Details
#parse ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/excise/base.rb', line 17 def parse @matches = pattern_expression.match(@string) tokens.each_with_index do |key, index| @output[key.to_sym] = @matches[index+1] end @output end |
#parse_string(string) ⇒ Object
25 26 27 28 |
# File 'lib/excise/base.rb', line 25 def parse_string(string) @string = string parse end |
#pattern_expression ⇒ Object
34 35 36 |
# File 'lib/excise/base.rb', line 34 def pattern_expression @pattern_expression ||= Regexp.new(@pattern.gsub(special_characters_expression, '\\\\\0').gsub(token_expression, "(\.+)")) end |
#special_characters_expression ⇒ Object
42 43 44 |
# File 'lib/excise/base.rb', line 42 def special_characters_expression SPECIAL_CHARACTERS_EXPRESSION end |
#token_expression ⇒ Object
38 39 40 |
# File 'lib/excise/base.rb', line 38 def token_expression TOKEN_EXPRESSION end |
#tokens ⇒ Object
30 31 32 |
# File 'lib/excise/base.rb', line 30 def tokens @tokens ||= @pattern.scan(token_expression).flatten end |