ls
This commit is contained in:
parent
3c65a01570
commit
a6fb0f99ba
1 changed files with 18 additions and 19 deletions
37
ls.rb
37
ls.rb
|
@ -1,40 +1,39 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
COLUMNS = 3
|
COLUMNS = 3
|
||||||
files = []
|
|
||||||
|
|
||||||
def run(files)
|
def run
|
||||||
served_files = serve_files(files)
|
listed_filenames = list_filenames
|
||||||
sliced_files = slice_files(served_files)
|
filenames_matrix = slice_filenames(listed_filenames)
|
||||||
filled_files = fill_files(sliced_files)
|
filled_filenames = fill_filenames(filenames_matrix)
|
||||||
arrange_files(filled_files)
|
arrange_filenames(filled_filenames)
|
||||||
end
|
end
|
||||||
|
|
||||||
def serve_files(_files)
|
def list_filenames
|
||||||
Dir.glob('*')
|
Dir.glob('*')
|
||||||
end
|
end
|
||||||
|
|
||||||
def slice_files(served_files)
|
def slice_filenames(listed_filenames)
|
||||||
columns_size = served_files.size.ceildiv(COLUMNS)
|
columns_size = listed_filenames.size.ceildiv(COLUMNS)
|
||||||
served_files.each_slice(columns_size).to_a
|
listed_filenames.each_slice(columns_size).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
def fill_files(sliced_files)
|
def fill_filenames(filenames_matrix)
|
||||||
array_size = sliced_files.map(&:size).max
|
array_size = filenames_matrix.map(&:size).max
|
||||||
sliced_files.each do |slice|
|
filenames_matrix.each do |slice|
|
||||||
slice << '' while slice.size < array_size
|
slice << '' while slice.size < array_size
|
||||||
end
|
end
|
||||||
sliced_files.transpose
|
filenames_matrix.transpose
|
||||||
end
|
end
|
||||||
|
|
||||||
def arrange_files(filled_files)
|
def arrange_filenames(filled_filenames)
|
||||||
string_count = filled_files.flatten.map(&:size).max
|
filenames_count = filled_filenames.flatten.map(&:size).max
|
||||||
filled_files.each do |arrange|
|
filled_filenames.each do |arrange|
|
||||||
arrange.each do |arranged|
|
arrange.each do |arranged|
|
||||||
print arranged.ljust(string_count + 5)
|
print arranged.ljust(filenames_count + 5)
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
run(files)
|
run
|
||||||
|
|
Loading…
Reference in a new issue