-
Notifications
You must be signed in to change notification settings - Fork 36
initial commit #46
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?
initial commit #46
Conversation
|
I think this could be a bit more "object oriented". Consider the initializer taking the filename, preprocessing it to some degree, and a getter method to finish the work and retrieve the data you want. |
|
|
||
| # count all the words and add them to a hash | ||
| def countAllWords(cleanedText) | ||
| wordCount = {} |
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.
anytime you initialize a collection to then iteratively build it up is a clue to maybe use a method like .map or .reduce which are common in a lot of languages.
here i'd recommend using a method like .reduce or .each_with_object.
lines 37-46 could also be written:
cleaned_text.reduce(Hash.new(0)) { |hash,word| hash[word] += 1; hash }or
cleaned_text.each_with_object(Hash.new(0)) { |word, hash| hash[word] += 1}| # parse text | ||
| def run(filename) | ||
|
|
||
| # read the text file |
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 like the pipelining. Also see Mike Gee's comment on sticking some of this stuff into the constructor.
| require 'count_words' | ||
|
|
||
| describe CountWords do | ||
| it 'should be a Class' do |
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.
watch your spaces ;)
| end | ||
|
|
||
| it 'should read a file that exists' do | ||
| countWords = CountWords.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.
See betterspecs.org documentation on let
http://www.betterspecs.org/
@jaybobo
@mikegee