class Microjoin::JoinRespondant

Constants

KEYSET

Attributes

l[R]
mode[R]
r[R]

Public Class Methods

new(l,r) click to toggle source
# File lib/microjoin/join_respondant.rb, line 5
def initialize(l,r)
  @l, @r = l, r
end

Public Instance Methods

on(left: nil, right: nil) click to toggle source
# File lib/microjoin/join_respondant.rb, line 9
def on(left: nil, right: nil)
  if block_given?
    raise ArgumentError, 'Cannot specify both general and specialized join keys' unless [left, right].compact == []
    left = right = Proc.new
  end

  gl = l.group_by(&left)
  gr = r.group_by(&right)

  send("join_#{mode}", gl, gr)
end

Private Instance Methods

keyjoin(keyset, gl, gr) click to toggle source
# File lib/microjoin/join_respondant.rb, line 35
def keyjoin(keyset, gl, gr)
  keyset::(gl, gr).map { |k|
    vl = gl[k] || []
    vr = gr[k] || []
    [k, [vl, vr]]
  }.to_h
end
set_mode(mode) click to toggle source
# File lib/microjoin/join_respondant.rb, line 43
def set_mode(mode)
  @mode = mode
  self
end