<commit_before>require 'term/ansicolor'

puts "sploek initialized"

["on_green", "green", "underline", 
 "append_features", "on_yellow", 
 "yellow", "blink", "on_blue", "blue", 
 "uncolored", "rapid_blink", "on_magenta", 
 "reset", "magenta", "negative", 
 "on_cyan", "cyan", "concealed", 
 "attributes", "on_white", "white", 
 "underscore", "strikethrough", "bold", 
 "on_black", "black", "dark", "on_red", 
 "clear", "red", "coloring?", "italic"].each do |m|
  eval("def #{m}; Term::ANSIColor.#{m}; end")
end

def nl
  "\n"
end


def find_file match
  path = match.to_s.sub('_spec', '').sub(/^spec\//, '')

  locations = [
    File.join("app", path),
    File.join("lib", path),
    path
  ]
  if File.exist?(match.to_s) && match.to_s["_spec"].nil?
    match
  elsif path = locations.find {|x| File.exist?(x) }
    path
  end
end

def find_spec match
  locations = [
    File.join("spec", match[1] + "_spec.rb"),
    File.join("spec", match[2] + "_spec.rb"),
    File.join("spec", match[1].sub(/^app/, '') + "_spec.rb")
  ]
  if match[1] =~ /_spec$/
    match
  elsif specpath = locations.find {|x| File.exist?(x) }
    specpath
  end
end

def run_spec match
  specpath = find_spec(match)
  return unless specpath
  print magenta, "spec", reset, " ", specpath, nl
  # result = %x{ spec #{specpath} }


  if system("spec #{specpath}")
    system("clear")
    print magenta, "spec", reset, " ", specpath, nl
    print green, "success", reset, nl
    true
  else
    false
  end
end

def run_cmd(cmd, match)
  match = find_file(match)
  return unless match
  puts "=" * 80
  print magenta, cmd, reset, " ", match, nl
  system "#{cmd} #{match}"
end

watch("^(.*/(.*))\.rb$") do |md|
  system "clear"

  if run_spec(md)
    run_cmd("flog", md)
    run_cmd("reek", md)
  end
end<commit_msg>readability adjustment<commit_after>require 'term/ansicolor'

puts "sploek initialized"

["on_green", "green", "underline", 
 "append_features", "on_yellow", 
 "yellow", "blink", "on_blue", "blue", 
 "uncolored", "rapid_blink", "on_magenta", 
 "reset", "magenta", "negative", 
 "on_cyan", "cyan", "concealed", 
 "attributes", "on_white", "white", 
 "underscore", "strikethrough", "bold", 
 "on_black", "black", "dark", "on_red", 
 "clear", "red", "coloring?", "italic"].each do |m|
  eval("def #{m}; Term::ANSIColor.#{m}; end")
end

def nl
  "\n"
end


def find_file match
  path = match.to_s.sub('_spec', '').sub(/^spec\//, '')

  locations = [
    File.join("app", path),
    File.join("lib", path),
    path
  ]
  if File.exist?(match.to_s) && match.to_s["_spec"].nil?
    match
  elsif path = locations.find {|x| File.exist?(x) }
    path
  end
end

def find_spec match
  locations = [
    File.join("spec", match[1] + "_spec.rb"),
    File.join("spec", match[2] + "_spec.rb"),
    File.join("spec", match[1].sub(/^app/, '') + "_spec.rb")
  ]
  if match[1] =~ /_spec$/
    match
  elsif specpath = locations.find {|x| File.exist?(x) }
    specpath
  end
end

def run_spec match
  specpath = find_spec(match)
  return unless specpath
  print magenta, "spec", reset, " ", specpath, nl


  system("spec #{specpath}")
end

def run_cmd(cmd, match)
  match = find_file(match)
  return unless match
  puts "-" * 80
  print magenta, cmd, reset, " ", match, nl
  system "#{cmd} #{match}"
end

watch("^(.*/(.*))\.rb$") do |md|
  system "clear"

  if run_spec(md)
    run_cmd("flog", md)
    run_cmd("reek", md)
  end

  puts "=" * 80
end
{'fraction_non_alphanumeric': 0.20368744512730466, 'fraction_numerical': 0.004097161252560726, 'mean_word_length': 3.631436314363144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2716985', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1325, 'n_words': 317}