Class: Linkage::Expectations::Exhaustive

Inherits:
Linkage::Expectation show all
Defined in:
lib/linkage/expectations/exhaustive.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Linkage::Expectation

#decollation_needed?

Constructor Details

#initialize(comparator, threshold, mode) ⇒ Exhaustive

Returns a new instance of Exhaustive.



6
7
8
9
10
# File 'lib/linkage/expectations/exhaustive.rb', line 6

def initialize(comparator, threshold, mode)
  @comparator = comparator
  @threshold = threshold
  @mode = mode
end

Instance Attribute Details

#comparatorObject (readonly)

Returns the value of attribute comparator.



4
5
6
# File 'lib/linkage/expectations/exhaustive.rb', line 4

def comparator
  @comparator
end

#modeObject (readonly)

Returns the value of attribute mode.



4
5
6
# File 'lib/linkage/expectations/exhaustive.rb', line 4

def mode
  @mode
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



4
5
6
# File 'lib/linkage/expectations/exhaustive.rb', line 4

def threshold
  @threshold
end

Instance Method Details

#apply_to(dataset, side) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/linkage/expectations/exhaustive.rb', line 42

def apply_to(dataset, side)
  exprs =
    case side
    when :lhs
      comparator.lhs_args.collect { |arg| arg.to_expr.as(arg.name) }
    when :rhs
      comparator.rhs_args.collect { |arg| arg.to_expr.as(arg.name) }
    end
  dataset.select_more(*exprs)
end

#kindObject



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
# File 'lib/linkage/expectations/exhaustive.rb', line 12

def kind
  if @kind.nil?
    if @comparator.lhs_args.length != @comparator.rhs_args.length
      @kind = :cross
    else
      @kind = :self
      @comparator.lhs_args.each_with_index do |lhs_arg, index|
        rhs_arg = @comparator.rhs_args[index]
        if !lhs_arg.objects_equal?(rhs_arg)
          @kind = :cross
          break
        end
      end
    end

    # Check for dual-linkage.
    if @kind == :cross
      # Assume that all lhs arguments have the same dataset, as well
      # as all the rhs arguments. Only check the first argument of each
      # side.
      lhs_arg = @comparator.lhs_args[0]
      rhs_arg = @comparator.rhs_args[0]
      if !lhs_arg.datasets_equal?(rhs_arg)
        @kind = :dual
      end
    end
  end
  @kind
end

#satisfied?(score) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
# File 'lib/linkage/expectations/exhaustive.rb', line 53

def satisfied?(score)
  case mode
  when :equal
    score == threshold
  when :min
    score >= threshold
  end
end