class CodeCaser::Analyzer

This class scans the provided files to determine if any converted identifiers overlap with existing identifiers.

Public Class Methods

new(opts) click to toggle source
# File lib/code_caser/analyzer.rb, line 6
def initialize(opts)
  @converter               = opts.fetch(:converter)
  @files                   = PathConverter.new(opts.fetch(:path)).get_files
  @verbose                 = opts.fetch(:verbose, false)
  @existing_identifiers    = {}
  @new_identifiers         = {}
  @overlapping_identifiers = []
end

Public Instance Methods

analyze() click to toggle source
# File lib/code_caser/analyzer.rb, line 15
def analyze
  load_existing_identifiers
  @files.each { |f| analyze_file(f) if File.file?(f) }
  puts @existing_identifiers.keys.sort.inspect
  print_new_identifiers if @verbose
  @overlapping_identifiers = @new_identifiers.select {|k,v| @existing_identifiers.key?(k) }.keys
  print_overlap
end
analyze_file(file_path) click to toggle source
# File lib/code_caser/analyzer.rb, line 37
def analyze_file(file_path)
  puts "loading file: #{file_path}" if @verbose
  IO.foreach(file_path) { |line| analyze_line(line) }
end
load_existing_identifiers() click to toggle source
# File lib/code_caser/analyzer.rb, line 24
def load_existing_identifiers
  @files.each { |f| load_existing_identifiers_from_file(f) if File.file?(f) }
end
load_existing_identifiers_from_file(file_path) click to toggle source
# File lib/code_caser/analyzer.rb, line 28
def load_existing_identifiers_from_file(file_path)
  puts "loading file: #{file_path}" if @verbose
  IO.foreach(file_path) { |line| load_existing_identifiers_from_line(line) }
end
load_existing_identifiers_from_line(line) click to toggle source
# File lib/code_caser/analyzer.rb, line 33
def load_existing_identifiers_from_line(line)
  split_line(line).each { |l| @existing_identifiers[l] = true }
end
print_new_identifiers() click to toggle source
print_overlap() click to toggle source

Private Instance Methods

analyze_line(original_line) click to toggle source
# File lib/code_caser/analyzer.rb, line 58
def analyze_line(original_line)
  # discard anything after the ignore_after identifier
  original_identifiers = @converter.chop(original_line).split(/\W+/)
  original_identifiers.each do |identifier|
    if identifier != (new_identifier = @converter.convert_line(identifier))
      @new_identifiers[new_identifier] = identifier
    end
  end
end
split_line(line) click to toggle source
# File lib/code_caser/analyzer.rb, line 68
def split_line(line)
  @converter.chop(line).split(/\W+/)
end