Created
June 24, 2016 14:25
-
-
Save paulkmiller/7798d95ad8afcb28174b0f26bb3bd79a to your computer and use it in GitHub Desktop.
This file contains 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
file_path = ARGV[0] || "test.txt" | |
file = File.open(file_path, "r") | |
line_count = File.foreach(file_path).inject(0) {|c, line| c+1} | |
words_count = [] | |
lines = File.readlines(ARGV[0] || "test.txt") | |
text = lines.join | |
char_count = text.length | |
file.each_line do |line| | |
words = line.split | |
words.each do |word| | |
word = word.gsub(/[,()'"]/,'') | |
end | |
words_count << words.length | |
end | |
puts "Number of Lines: #{line_count}" | |
puts "Number of Words: #{words_count.inject(0){|sum,item| sum + item}}" | |
puts "Number of Characters: #{char_count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment