Last active
February 25, 2016 08:24
-
-
Save mat-staszczyk/317bbd857b6a259091c2 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
filename = ARGV[0] | |
class Analyzer | |
attr_reader :text | |
def initialize(filename) | |
@file = File.open(filename, "r+") | |
@text = generate_text | |
@file.close | |
end | |
def line_count | |
@file.readlines.length | |
end | |
def character_count | |
@text.clone.gsub(/\s+/, '').length | |
end | |
def total_length | |
@text.length | |
end | |
def words_count | |
@text.split.length | |
end | |
def sentence_count | |
@text.split(/\.|\?|\!/).length | |
end | |
def paragraph_count | |
@text.split(/\n\n/).length | |
end | |
def averages | |
puts "#{sentence_count / paragraph_count} sentences per paragraph (average)." | |
puts "#{words_count / sentence_count} words per sentence (average)." | |
end | |
private | |
def generate_text | |
string = '' | |
@file.each { |line| string << line } | |
string | |
end | |
end | |
test = Analyzer.new(filename) | |
test.averages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment