lib/excise/base.rb in excise-0.2.0 vs lib/excise/base.rb in excise-0.2.1

- old
+ new

@@ -3,29 +3,23 @@ module Excise class Base TOKEN_EXPRESSION = /{([^{}\t\r\n]+)}/.freeze SPECIAL_CHARACTERS_EXPRESSION = /[\\\^\$\*\+\.\?\(\)\[\]]/.freeze - attr_accessor :string - - def initialize(pattern, string = "") + def initialize(pattern) @pattern = pattern - @string = string - - @output = {} end - def parse - @matches = pattern_expression.match(@string) + def parse(string) + @matches = pattern_expression.match(string) + + output = {} + tokens.each_with_index do |key, index| - @output[key.to_sym] = @matches[index+1] + output[key.to_sym] = @matches[index+1] end - @output - end - def parse_string(string) - @string = string - parse + output end def tokens @tokens ||= @pattern.scan(token_expression).flatten end