Skip to content

Instantly share code, notes, and snippets.

@aytch
Created September 15, 2016 02:45
Show Gist options
  • Select an option

  • Save aytch/d64484f1c625fb8c6dfe35559f75ea42 to your computer and use it in GitHub Desktop.

Select an option

Save aytch/d64484f1c625fb8c6dfe35559f75ea42 to your computer and use it in GitHub Desktop.
if ARGV == []
puts "Error: File path required"
exit(101)
end
ARGV.each do |file|
if File.exists?(file) == false
puts "Error: File does not exist"
exit(102)
end
if File.directory?(file)
puts "Error: File path exists, but is a directory"
exit(103)
end
puts "Owner: #{File.stat(file).uid}"
puts "Group: #{File.stat(file).gid}"
puts "Size: #{File.stat(file).size}"
f = File.open(file, 'r')
puts "Line Count: #{f.readlines.size}"
# this doesn't work, but I moved on because of time constraints. Shouldn't be terribly hard from here.
wc = 0
f.each_line do |line|
words = line.split
puts words
words.each do |word|
wc = wc + 1
return wc
end
return wc
end
puts "Word Count: #{wc}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment