lib/picky/tokenizer.rb in picky-4.20.0 vs lib/picky/tokenizer.rb in picky-4.20.1
- old
+ new
@@ -57,15 +57,14 @@
TOKENIZER
end
# Stopwords.
#
- # We only allow regexps (even if string would be okay
- # too for gsub! - it's too hard to understand)
+ # We even allow Strings even if it's hard to understand.
#
def stopwords regexp
- check_argument_in __method__, Regexp, regexp
+ check_argument_in __method__, [Regexp, String, FalseClass], regexp
@remove_stopwords_regexp = regexp
end
def remove_stopwords text
text.gsub! @remove_stopwords_regexp, EMPTY_STRING if @remove_stopwords_regexp
text
@@ -81,11 +80,11 @@
#
# We only allow regexps (even if string would be okay
# too for gsub! - it's too hard to understand)
#
def removes_characters regexp
- check_argument_in __method__, Regexp, regexp
+ check_argument_in __method__, [Regexp, FalseClass], regexp
@removes_characters_regexp = regexp
end
def remove_illegals text
text.gsub! @removes_characters_regexp, EMPTY_STRING if @removes_characters_regexp
text
@@ -190,11 +189,14 @@
@max_words && words.size > @max_words
end
# Checks if the right argument type has been given.
#
- def check_argument_in method, type, argument, &condition
- raise ArgumentError.new "Application##{method} takes a #{type} as argument, not a #{argument.class}." unless type === argument
+ def check_argument_in method, types, argument, &condition
+ types = [*types]
+ unless types.any? { |type| type === argument }
+ raise ArgumentError.new "Application##{method} takes any of #{types.join(', ')} as argument, but not a #{argument.class}."
+ end
end
attr_reader :substituter, :stemmer
alias substituter? substituter
alias stemmer? stemmer
\ No newline at end of file