Class: CaDOVe::Analytics::ClassMatchKey

Inherits:
Object
  • Object
show all
Defined in:
lib/cadove/models/analytics/comparison.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ ClassMatchKey

Returns a new instance of ClassMatchKey.



62
63
64
65
# File 'lib/cadove/models/analytics/comparison.rb', line 62

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



66
67
68
# File 'lib/cadove/models/analytics/comparison.rb', line 66

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



66
67
68
# File 'lib/cadove/models/analytics/comparison.rb', line 66

def right
  @right
end

Class Method Details

.align(left_keys, right_keys, override = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cadove/models/analytics/comparison.rb', line 68

def self.align(left_keys, right_keys, override={})
  override = override.with_indifferent_access

  matches = []
  left_keys.each do |left_key|
    found =
      if m = override_match(left_key, right_keys, override)
        right_keys.delete(m)
      elsif right_keys.include?(left_key)
        right_keys.delete(left_key)
      end

      matches << new(left_key, found)
  end
  
  right_keys.each do |right_key|
    matches << new(nil, right_key)
  end
  
  matches.sort
end

.override_match(left_key, right_keys, override = {}) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/cadove/models/analytics/comparison.rb', line 90

def self.override_match(left_key, right_keys, override={})
  if override.has_key?(left_key) && right_keys.include?(override[left_key].to_s)
    override[left_key].to_s
  elsif override.invert.has_key?(left_key) && right_keys.include?(override.invert[left_key].to_s)
    override.invert[left_key].to_s
  end
end

Instance Method Details

#<=>(other) ⇒ Object



98
99
100
# File 'lib/cadove/models/analytics/comparison.rb', line 98

def <=>(other)
  display <=> other.display
end

#displayObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cadove/models/analytics/comparison.rb', line 102

def display
  return if left.nil? && right.nil?
  
  if left && right.nil?
    left
  elsif right && left.nil?
    right
  elsif left == right
    left
  elsif left != right
    "#{left} => #{right}"
  end
end