Class: Klee::Collaborators

Inherits:
Object
  • Object
show all
Defined in:
lib/klee/collaborators.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(const) ⇒ Collaborators

Returns a new instance of Collaborators.



7
8
9
# File 'lib/klee/collaborators.rb', line 7

def initialize(const)
  @const = const
end

Instance Attribute Details

#constObject (readonly)

Returns the value of attribute const.



10
11
12
# File 'lib/klee/collaborators.rb', line 10

def const
  @const
end

Instance Method Details

#additional_processing_typesObject



16
# File 'lib/klee/collaborators.rb', line 16

def additional_processing_types = [:DOT, :BRACKET_LEFT]

#identifier_with_additional_processingObject



18
19
20
21
22
23
24
25
# File 'lib/klee/collaborators.rb', line 18

def identifier_with_additional_processing
  lexed.value.each_cons(2).filter_map do |(token, next_token)|
    if token.first.type == :IDENTIFIER &&
        additional_processing_types.include?(next_token.first.type)
      token.first.value
    end
  end
end

#lexedObject



12
13
14
# File 'lib/klee/collaborators.rb', line 12

def lexed
  Prism.lex_file(Object.const_source_location(const.name).first)
end

#rankObject



31
32
33
34
35
36
37
38
39
# File 'lib/klee/collaborators.rb', line 31

def rank
  tally.group_by do |_, count|
    count
  end.sort.reverse.to_h.transform_values do |value|
    value.map(&:first)
  end.reject do |key, value|
    value.empty? || key < 3
  end
end

#tallyObject



27
28
29
# File 'lib/klee/collaborators.rb', line 27

def tally
  identifier_with_additional_processing.tally
end