Skip to content

Commit

Permalink
Fix Hound
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeymorozov committed Mar 4, 2024
1 parent 179b194 commit c9d99a6
Showing 1 changed file with 32 additions and 42 deletions.
74 changes: 32 additions & 42 deletions process/fix_name_to_match_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def call

private

# remove name attr on return (same name or missing spaces)
# keep if case sensitive
# restore spaces and keep if space-dependent and case-sensitive
# let fix custom list by hand
def process(path)
h = YAML.load_file(path)
key = key(path)
Expand All @@ -37,17 +33,7 @@ def process(path)
return
end

if h["name"] == gen_name
@equal_list << [key, h["name"], gen_name]
elsif h["name"].gsub(" ", "") == gen_name.gsub(" ", "")
@space_equal_list << [key, h["name"], gen_name]
elsif h["name"].casecmp?(gen_name)
@case_sensitive_list << [key, h["name"], gen_name]
elsif h["name"].gsub(" ", "").casecmp?(gen_name.gsub(" ", ""))
@space_and_case_sensitive_list << [key, h["name"], gen_name]
else
@custom_list << [key, h["name"], gen_name]
end
choose_list(key, h["name"], gen_name)
end

def key(path)
Expand All @@ -59,32 +45,44 @@ def name(key)
last_part.split.map(&:capitalize).join(" ")
end

def print_results
puts "No name list: #{@no_name_list.size}" # ok, nothing to do

puts
puts "Equal list size: #{@equal_list.size}" # ok, can be kept

puts
puts "Space equal list size: #{@space_equal_list.size}" # remove, so not to bother with renaming

puts
puts "Case-sensitive list:"
print_list(@case_sensitive_list) # ok, keep
# rubocop:disable Metrics/MethodLength
def choose_list(key, current_name, gen_name)
if current_name == gen_name
@equal_list << [key, current_name, gen_name]
elsif current_name.gsub(" ", "") == gen_name.gsub(" ", "")
@space_equal_list << [key, current_name, gen_name]
elsif current_name.casecmp?(gen_name)
@case_sensitive_list << [key, current_name, gen_name]
elsif current_name.gsub(" ", "").casecmp?(gen_name.gsub(" ", ""))
@space_and_case_sensitive_list << [key, current_name, gen_name]
else
@custom_list << [key, current_name, gen_name]
end
end
# rubocop:enable Metrics/MethodLength

puts
puts "Space and case-sensitive list:" # restore space
print_list(@space_and_case_sensitive_list)
def print_results
print_size(@no_name_list, "No name")
print_size(@equal_list, "Equal")
print_size(@space_equal_list, "Space equal")
print_list(@case_sensitive_list, "Case-sensitive")
print_list(@space_and_case_sensitive_list, "Space and case-sensitive")
print_list(@custom_list, "Custom")
end

def print_size(list, label)
puts "#{label} list: #{list.size}"
puts
puts "Custom list:"
print_list(@custom_list) # fix manually
end

def print_list(list)
def print_list(list, label)
puts "#{label} list:"

list.each do |key, name, gen_name|
puts "#{key}: #{name} => #{gen_name}"
end

puts
end

def fix_name_attr
Expand Down Expand Up @@ -128,18 +126,10 @@ def rewrite_name_with_yaml(key, name)
h["name"] = name
puts "Path: #{path}, #{YAML.dump(h).slice(0, 100)}"
File.write(path, YAML.dump(h))
# first:
# read as YAML into hash
# change hash, save file
#
# second:
# read file into string
# replace name attribute with multiline regex
# write content into file
end

def remove_name(list)
list.each do |key, name, gen_name|
list.each do |key, _name, _gen_name|
unset_name_and_save(key)
end
end
Expand Down

0 comments on commit c9d99a6

Please sign in to comment.