Class: Microjoin::JoinRespondant

Inherits:
Object
  • Object
show all
Defined in:
lib/microjoin/join_respondant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(l, r) ⇒ JoinRespondant

Returns a new instance of JoinRespondant.



5
6
7
# File 'lib/microjoin/join_respondant.rb', line 5

def initialize(l,r)
  @l, @r = l, r
end

Instance Attribute Details

#lObject (readonly)

Returns the value of attribute l.



3
4
5
# File 'lib/microjoin/join_respondant.rb', line 3

def l
  @l
end

#modeObject (readonly)

Returns the value of attribute mode.



3
4
5
# File 'lib/microjoin/join_respondant.rb', line 3

def mode
  @mode
end

#rObject (readonly)

Returns the value of attribute r.



3
4
5
# File 'lib/microjoin/join_respondant.rb', line 3

def r
  @r
end

Instance Method Details

#on(left: nil, right: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# 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