Class: Bmg::Operator::Rxmatch
- Inherits:
-
Object
- Object
- Bmg::Operator::Rxmatch
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/rxmatch.rb
Overview
Rxmatch operator.
Filters operand’s tuples to those whose attributes match a given string or regular expression.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ case_sensitive: false }
Constants included from Algebra
Instance Attribute Summary
Attributes included from Unary
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, operand, attrs, matcher, options) ⇒ Rxmatch
constructor
A new instance of Rxmatch.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_json, #update, #visit, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #matching, #page, #project, #rename, #restrict, #rxmatch, #spied, #union, #unspied
Constructor Details
#initialize(type, operand, attrs, matcher, options) ⇒ Rxmatch
Returns a new instance of Rxmatch.
16 17 18 19 20 21 22 |
# File 'lib/bmg/operator/rxmatch.rb', line 16 def initialize(type, operand, attrs, matcher, ) @type = type @operand = operand @attrs = attrs @matcher = matcher @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#each ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bmg/operator/rxmatch.rb', line 34 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 |
#to_ast ⇒ Object
46 47 48 |
# File 'lib/bmg/operator/rxmatch.rb', line 46 def to_ast [ :rxmatch, operand.to_ast, attrs.dup, matcher, .dup ] end |