$stdin.read
This commit is contained in:
parent
b0d547fda0
commit
d38889ea48
1 changed files with 8 additions and 9 deletions
17
wc.rb
17
wc.rb
|
@ -10,7 +10,7 @@ def parse_options
|
|||
opts.on('-c') { options[:bytes] = true }
|
||||
end.parse!
|
||||
options = { bytes: true, lines: true, words: true } if options.empty?
|
||||
[options, ARGV.empty? ? [ARGF] : ARGV]
|
||||
[options, ARGV.empty? ? ['-'] : ARGV]
|
||||
end
|
||||
|
||||
def count_file_stats(input)
|
||||
|
@ -24,13 +24,12 @@ def count_file_stats(input)
|
|||
end
|
||||
|
||||
def process_input(source)
|
||||
if source == ARGF || File.exist?(source)
|
||||
input = source == ARGF ? ARGF.read : File.read(source)
|
||||
count_file_stats(input)
|
||||
else
|
||||
puts "wc: #{source}: そのようなファイルやディレクトリはありません"
|
||||
exit
|
||||
end
|
||||
input = if source == '-'
|
||||
$stdin.read
|
||||
else
|
||||
File.read(source)
|
||||
end
|
||||
count_file_stats(input)
|
||||
end
|
||||
|
||||
def update_totals(totals, stats)
|
||||
|
@ -50,7 +49,7 @@ def format_result(stats, max_widths, options)
|
|||
end
|
||||
|
||||
def print_result(result, source)
|
||||
puts "#{result} #{source == ARGF ? '' : source}"
|
||||
puts "#{result} #{source == '-' ? '' : source}"
|
||||
end
|
||||
|
||||
def print_total(total_stats, max_widths, options)
|
||||
|
|
Loading…
Reference in a new issue