Class: Lhm::Intersection

Inherits:
Object
  • Object
show all
Defined in:
lib/lhm/intersection.rb

Overview

Determine and format columns common to origin and destination.

Instance Method Summary collapse

Constructor Details

#initialize(origin, destination, insert_trigger_additions) ⇒ Intersection

Returns a new instance of Intersection.



7
8
9
10
11
# File 'lib/lhm/intersection.rb', line 7

def initialize(origin, destination, insert_trigger_additions)
  @origin = origin
  @destination = destination
  @insert_trigger_additions = insert_trigger_additions
end

Instance Method Details

#combined_joinedObject



25
26
27
# File 'lib/lhm/intersection.rb', line 25

def combined_joined
  (escaped + escaped_insert).join(", ")
end

#combined_typed(type) ⇒ Object



29
30
31
# File 'lib/lhm/intersection.rb', line 29

def combined_typed(type)
  (common.map { |name| qualified(name, type)  } + @insert_trigger_additions.values.map { |name| parenthesize(name) }).join(", ")
end

#commonObject



13
14
15
# File 'lib/lhm/intersection.rb', line 13

def common
  (@origin.columns.keys & @destination.columns.keys).sort
end

#escapedObject



33
34
35
# File 'lib/lhm/intersection.rb', line 33

def escaped
  common.map { |name| tick(name)  }
end

#escaped_insertObject



21
22
23
# File 'lib/lhm/intersection.rb', line 21

def escaped_insert
  insert.map { |name| tick(name)  }
end

#insertObject



17
18
19
# File 'lib/lhm/intersection.rb', line 17

def insert
  @insert_trigger_additions.keys
end

#joinedObject



37
38
39
# File 'lib/lhm/intersection.rb', line 37

def joined
  escaped.join(", ")
end

#typed(type) ⇒ Object



45
46
47
# File 'lib/lhm/intersection.rb', line 45

def typed(type)
  common.map { |name| qualified(name, type)  }.join(", ")
end

#typed_unjoined(type) ⇒ Object



41
42
43
# File 'lib/lhm/intersection.rb', line 41

def typed_unjoined(type)
  common.map { |name| qualified(name, type)  }
end