Skip to content

Commit

Permalink
refactor: split into two methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushpoddar committed Jun 7, 2023
1 parent 6f7f4ab commit 305e248
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,32 @@ def file_color(file, key)

def options(content)
if content.directory?
key = content.name.downcase.to_sym
key = @folder_aliases[key] unless @folders.key? key
key = :folder if key.nil?
color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]
group = :folders
options_directory(content).values_at(:key, :color, :group)
else
key = File.extname(content.name).delete_prefix('.').downcase.to_sym
key = @file_aliases[key] unless @files.key? key
color = file_color(content, key)
group = @files.key?(key) ? :recognized_files : :unrecognized_files
key = :file if key.nil?
options_file(content).values_at(:key, :color, :group)
end
end

def options_directory(content)
key = content.name.downcase.to_sym
key = @folder_aliases[key] unless @folders.key?(key)
key = :folder if key.nil?

color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]

{key: key, color: color, group: :folders}
end

def options_file(content)
key = File.extname(content.name).delete_prefix('.').downcase.to_sym
key = @file_aliases[key] unless @files.key?(key)

color = file_color(content, key)
group = @files.key?(key) ? :recognized_files : :unrecognized_files

key = :file if key.nil?

[key, color, group]
{key: key, color: color, group: group}
end

def tree_contents(path)
Expand Down

0 comments on commit 305e248

Please sign in to comment.