Class: RuboCop::Gradual::Process::Matcher

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubocop/gradual/process/matcher.rb

Overview

Matcher matches two files arrays and returns an object with matched map.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys, values, matched) ⇒ Matcher

Returns a new instance of Matcher.



12
13
14
15
16
# File 'lib/rubocop/gradual/process/matcher.rb', line 12

def initialize(keys, values, matched)
  @unmatched_keys = keys - matched.keys
  @unmatched_values = values - matched.values
  @matched = matched
end

Instance Attribute Details

#matchedObject (readonly)

Returns the value of attribute matched.



10
11
12
# File 'lib/rubocop/gradual/process/matcher.rb', line 10

def matched
  @matched
end

#unmatched_keysObject (readonly)

Returns the value of attribute unmatched_keys.



10
11
12
# File 'lib/rubocop/gradual/process/matcher.rb', line 10

def unmatched_keys
  @unmatched_keys
end

#unmatched_valuesObject (readonly)

Returns the value of attribute unmatched_values.



10
11
12
# File 'lib/rubocop/gradual/process/matcher.rb', line 10

def unmatched_values
  @unmatched_values
end

Class Method Details

.new(keys, values, property) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/gradual/process/matcher.rb', line 23

def new(keys, values, property)
  matched = keys.each_with_object({}) do |key, result|
    match_value = values.find do |value|
      key.public_send(property) == value.public_send(property)
    end
    result[key] = match_value if match_value
  end

  super(keys, values, matched)
end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
# File 'lib/rubocop/gradual/process/matcher.rb', line 18

def each(&block)
  @matched.each(&block)
end