lib/goodcheck/pattern.rb in goodcheck-1.0.0 vs lib/goodcheck/pattern.rb in goodcheck-1.1.0

- old
+ new

@@ -18,15 +18,15 @@ options |= Regexp::MULTILINE if multiline new(source: regexp, regexp: Regexp.compile(regexp, options)) end - def self.token(tokens) - new(source: tokens, regexp: compile_tokens(tokens)) + def self.token(tokens, case_insensitive:) + new(source: tokens, regexp: compile_tokens(tokens, case_insensitive: case_insensitive)) end - def self.compile_tokens(source) + def self.compile_tokens(source, case_insensitive:) tokens = [] s = StringScanner.new(source) until s.eos? case @@ -49,9 +49,12 @@ if tokens.last =~ /\p{Letter}\Z/ tokens.last << '\b' end - Regexp.new(tokens.join('\s*').gsub(/\\s\*(\\s\+\\s\*)+/, '\s+'), Regexp::MULTILINE) + options = Regexp::MULTILINE + options |= Regexp::IGNORECASE if case_insensitive + + Regexp.new(tokens.join('\s*').gsub(/\\s\*(\\s\+\\s\*)+/, '\s+'), options) end end end