lib/bmg/operator/rxmatch.rb in bmg-0.9.0 vs lib/bmg/operator/rxmatch.rb in bmg-0.9.1

- old
+ new

@@ -7,11 +7,13 @@ # given string or regular expression. # class Rxmatch include Operator::Unary - DEFAULT_OPTIONS = {} + DEFAULT_OPTIONS = { + case_sensitive: false + } def initialize(type, operand, attrs, matcher, options) @type = type @operand = operand @attrs = attrs @@ -21,14 +23,23 @@ protected attr_reader :attrs, :matcher, :options + def case_sensitive? + !!options[:case_sensitive] + end + public def each @operand.each do |tuple| against = attrs.map{|a| tuple[a] }.join(" ") + matcher = self.matcher + unless case_sensitive? + against = against.downcase + matcher = matcher.downcase if matcher.is_a?(String) + end yield(tuple) if against.match(matcher) end end def to_ast