Class: Kiba::Extend::Utils::Lookup::MultivalPairs

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/utils/lookup/multival_pairs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pair:, row:, sep:, mergerow: {}) ⇒ MultivalPairs

Returns a new instance of MultivalPairs.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kiba/extend/utils/lookup/multival_pairs.rb', line 10

def initialize(pair:, row:, sep:, mergerow: {})
  @result = []
  pair = pair.map { |e| e.split("::") }
  # convert row or mergerow fieldnames to symbols
  pair = pair.each { |arr| arr[1] = arr[1].to_sym if arr[0]["row"] }
  # fetch or convert values for comparison
  pair = pair.map do |arr|
    case arr[0]
    when "row"
      [row.fetch(arr[1], "")].map do |e|
        (e.nil? || e.empty?) ? "%comparenothing%" : e
      end
    when "mvrow"
      row.fetch(arr[1], "").split(sep).map do |e|
        (e.nil? || e.empty?) ? "%comparenothing%" : e
      end
    when "mergerow"
      [mergerow.fetch(arr[1], "")].map do |e|
        (e.nil? || e.empty?) ? "%comparenothing%" : e
      end
    when "mvmergerow"
      mergerow.fetch(arr[1], "").split(sep).map do |e|
        (e.nil? || e.empty?) ? "%comparenothing%" : e
      end
    when "revalue"
      "revalue::#{arr[1]}"
    when "value"
      arr[1]
    end
  end
  pair[0].product(pair[1]).each do |mvpair|
    @result << mvpair.map do |e|
      e.start_with?("revalue") ? e : "value::#{e}"
    end
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/kiba/extend/utils/lookup/multival_pairs.rb', line 8

def result
  @result
end