lib/goodcheck/pattern.rb in goodcheck-1.1.0 vs lib/goodcheck/pattern.rb in goodcheck-1.2.0
- old
+ new
@@ -6,27 +6,27 @@
def initialize(source:, regexp:)
@source = source
@regexp = regexp
end
- def self.literal(literal, case_insensitive:)
- new(source: literal, regexp: Regexp.compile(Regexp.escape(literal), case_insensitive))
+ def self.literal(literal, case_sensitive:)
+ new(source: literal, regexp: Regexp.compile(Regexp.escape(literal), !case_sensitive))
end
- def self.regexp(regexp, case_insensitive:, multiline:)
+ def self.regexp(regexp, case_sensitive:, multiline:)
options = 0
- options |= Regexp::IGNORECASE if case_insensitive
+ options |= Regexp::IGNORECASE unless case_sensitive
options |= Regexp::MULTILINE if multiline
new(source: regexp, regexp: Regexp.compile(regexp, options))
end
- def self.token(tokens, case_insensitive:)
- new(source: tokens, regexp: compile_tokens(tokens, case_insensitive: case_insensitive))
+ def self.token(tokens, case_sensitive:)
+ new(source: tokens, regexp: compile_tokens(tokens, case_sensitive: case_sensitive))
end
- def self.compile_tokens(source, case_insensitive:)
+ def self.compile_tokens(source, case_sensitive:)
tokens = []
s = StringScanner.new(source)
until s.eos?
case
@@ -50,10 +50,10 @@
if tokens.last =~ /\p{Letter}\Z/
tokens.last << '\b'
end
options = Regexp::MULTILINE
- options |= Regexp::IGNORECASE if case_insensitive
+ options |= Regexp::IGNORECASE unless case_sensitive
Regexp.new(tokens.join('\s*').gsub(/\\s\*(\\s\+\\s\*)+/, '\s+'), options)
end
end
end