diff --git a/wc.rb b/wc.rb index b9ffa85..25aef9d 100644 --- a/wc.rb +++ b/wc.rb @@ -58,16 +58,20 @@ def print_total(total_stats, max_widths, options) puts "#{total_result} 合計" end -options, input_sources = parse_options -total_stats = [0, 0, 0] -max_widths = [0, 0, 0] +def process_input_sources(input_sources, options) + total_stats = [0, 0, 0] + max_widths = [0, 0, 0] -input_sources.each do |source| - stats = process_input(source) - total_stats = update_totals(total_stats, stats) - max_widths = update_max_widths(max_widths, stats) - result = format_result(stats, max_widths, options) - print_result(result, source) + input_sources.each do |source| + stats = process_input(source) + total_stats = update_totals(total_stats, stats) + max_widths = update_max_widths(max_widths, stats) + result = format_result(stats, max_widths, options) + print_result(result, source) + end + + print_total(total_stats, max_widths, options) if input_sources.size > 1 end -print_total(total_stats, max_widths, options) if input_sources.size > 1 +options, input_sources = parse_options +process_input_sources(input_sources, options)