Class: Bmg::Operator::Image
- Inherits:
-
Object
- Object
- Bmg::Operator::Image
- Includes:
- Binary
- Defined in:
- lib/bmg/operator/image.rb
Overview
Image operator.
Extends each tuple with its image in right.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ # Whether we need to convert each image as an Array, # instead of keeping a Relation instance array: false }
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, left, right, as, on, options = {}) ⇒ Image
constructor
A new instance of Image.
- #to_ast ⇒ Object
Methods included from Bmg::Operator
Methods included from Relation
#debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_json, #update, #visit, #with_typecheck, #without_typecheck, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #matching, #materialize, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #union, #unspied
Methods included from Algebra::Shortcuts
#image, #join, #matching, #not_matching, #prefix, #rxmatch, #suffix
Constructor Details
#initialize(type, left, right, as, on, options = {}) ⇒ Image
Returns a new instance of Image.
19 20 21 22 23 24 25 26 |
# File 'lib/bmg/operator/image.rb', line 19 def initialize(type, left, right, as, on, = {}) @type = type @left = left @right = right @as = as @on = on @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#each ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bmg/operator/image.rb', line 34 def each index = Hash.new{|h,k| h[k] = empty_image } right.each_with_object(index) do |t, index| key = tuple_project(t, on) index[key].operand << tuple_image(t, on) end if [:array] index = index.each_with_object({}) do |(k,v),ix| ix[k] = v.to_a end end left.each do |tuple| key = tuple_project(tuple, on) image = index[key] || ([:array] ? [] : empty_image) yield tuple.merge(as => image) end end |
#to_ast ⇒ Object
52 53 54 |
# File 'lib/bmg/operator/image.rb', line 52 def to_ast [ :image, left.to_ast, right.to_ast, as, on, .dup ] end |