Class: Kiba::Extend::Utils::Lookup::PairEquality

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PairEquality.



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
# File 'lib/kiba/extend/utils/lookup/pair_equality.rb', line 10

def initialize(pair:, row:, mergerow: {})
  comparison_type = :equals
  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], "%field does not exist%")
    when "mergerow"
      mergerow.fetch(arr[1], "%field does not exist%")
    when "revalue"
      comparison_type = :match
      arr[1] = "^#{arr[1]}$"
      Regexp.new(arr[1])
    when "value"
      arr[1]
    end
  end

  unless pair.include?(nil) && pair.include?("")
    # replace nil value with empty string for comparison
    pair = pair.map { |e| e.nil? ? "" : e }
  end

  case comparison_type
  when :equals
    @result = pair[0] == pair[1]
  when :match
    @result = pair[0].match?(pair[1])
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end