Created
September 15, 2016 02:45
-
-
Save aytch/d64484f1c625fb8c6dfe35559f75ea42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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