-
Notifications
You must be signed in to change notification settings - Fork 36
Ready for evaluation #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,43 @@ | |||
| class CountWords | |||
|
|
|||
| attr_accessor :word_count | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This word_count isn't used yet. You can probably delete all the @@s and then you would be using it.
| count_file = File.open(file, "r") | ||
| count_file.each_line do |line| | ||
| next if line.empty? | ||
| @@word_count = Hash.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we start with a fresh Hash on every line. Is that a bug?
| word = line.split | ||
| word.each do |wrd| | ||
| next if wrd !~ /(\w+)/ | ||
| wrd = wrd[/(\w+)/] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting the line, iterating, and making sure each word matches \w+, can be simplified using String#scan.
| @@word_count[wrd] = 1 | ||
| end | ||
| end | ||
| display_word_count_asc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to not display while you build up the data. How about if the client code (outside this class) asks for the display something like:
word_counter = CountWords.new
word_counter.count_words_from_file("speech.txt")
word_counter.display_word_count_asc| def display_word_count_asc | ||
| puts "" | ||
| puts "'''''" | ||
| @@word_count.sort{|a,b| a[1]<=>b[1]}.each { |word| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubyists tend to use {} for single line block, and do/end for multiline blocks.
Check out Rubocop for automated checks for stuff like this. It enforces this style guide.
No description provided.