Class: Bmg::Operator::Rxmatch

Inherits:
Object
  • Object
show all
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
}

Instance Attribute Summary

Attributes included from Bmg::Operator

#type

Instance Method Summary collapse

Methods included from Unary

#bind

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap

Methods included from Algebra::Shortcuts

#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where

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, options)
  @type = type
  @operand = operand
  @attrs = attrs
  @matcher = matcher
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#eachObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bmg/operator/rxmatch.rb', line 34

def each
  return to_enum unless block_given?
  @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_astObject



47
48
49
# File 'lib/bmg/operator/rxmatch.rb', line 47

def to_ast
  [ :rxmatch, operand.to_ast, attrs.dup, matcher, options.dup ]
end