完成!!!!!!!!!?

This commit is contained in:
Rikuoh Tsujitani 2024-07-31 23:52:23 +09:00
parent 66768a11ed
commit e161f37523
Signed by: riq0h
GPG key ID: 010F09DEA298C717

6
wc.rb
View file

@ -9,7 +9,7 @@ def main
max_widths = calculate_max_widths(total_stat) max_widths = calculate_max_widths(total_stat)
file_stats << total_stat if filenames.size > 1 file_stats << total_stat if filenames.size > 1
file_stats.each { |file_stat| puts format_result(file_stat, max_widths, options).join(' ') } file_stats.each { |file_stat| puts format_row(file_stat, max_widths, options) }
end end
def parse_options def parse_options
@ -50,11 +50,11 @@ def calculate_max_widths(total_stat)
%i[lines words bytes].to_h { |key| [key, total_stat[key].to_s.length] } %i[lines words bytes].to_h { |key| [key, total_stat[key].to_s.length] }
end end
def format_result(stats, max_widths, options) def format_row(stats, max_widths, options)
result = %i[lines words bytes].filter_map do |key| result = %i[lines words bytes].filter_map do |key|
stats[key].to_s.rjust(max_widths[key]) if options[key] stats[key].to_s.rjust(max_widths[key]) if options[key]
end end
result << stats[:filename] [*result, stats[:filename]].join(' ')
end end
main main