Permalink
Browse files

+ Extract RegexpWrapper (wraps Tokenizer Regexp to invert split call …

…mechanism)
  • Loading branch information...
1 parent b522524 commit 26c5fb0c8dec0168c6338ad06eeaaf44c89e02b5 @floere committed Dec 3, 2012
Showing with 22 additions and 13 deletions.
  1. +1 −0 server/lib/picky/loader.rb
  2. +2 −13 server/lib/picky/tokenizer.rb
  3. +19 −0 server/lib/picky/tokenizer/regexp_wrapper.rb
@@ -265,6 +265,7 @@ def load_user_interface
load_api
load_logging
load_relative 'source'
+ load_relative 'tokenizer/regexp_wrapper'
load_relative 'tokenizer'
# load_relative 'rack/harakiri' # Needs to be explicitly loaded/required.
load_relative 'character_substituters/west_european'
@@ -105,17 +105,6 @@ def splits_text_on thing
RegexpWrapper.new thing
end
end
- class RegexpWrapper
- def initialize regexp
- @regexp = regexp
- end
- def split text
- text.split @regexp
- end
- def source
- @regexp.source
- end
- end
def split text
@splits_text_on.split text
end
@@ -124,8 +113,8 @@ def split text
#
# We only allow arrays.
#
- # TODO 5.0 Rename to normalizes(config)
- # TODO 5.0 Rename to normalize(text)
+ # TODO 5.0 Rename to normalizes(config) or normalizes_words
+ # TODO 5.0 Rename to normalize(text) or normalize_words
#
def normalizes_words regexp_replaces
raise ArgumentError.new "#{__method__} takes an Array of replaces as argument, not a #{regexp_replaces.class}." unless regexp_replaces.respond_to?(:to_ary) || regexp_replaces.respond_to?(:normalize_with_patterns)
@@ -0,0 +1,19 @@
+class RegexpWrapper
+
+ def initialize regexp
+ @regexp = regexp
+ end
+
+ def split text
+ text.split @regexp
+ end
+
+ def source
+ @regexp.source
+ end
+
+ def method_missing name, *args, &block
+ @regexp.send name, *args, &block
+ end
+
+end

0 comments on commit 26c5fb0

Please sign in to comment.