-
-
Notifications
You must be signed in to change notification settings - Fork 50
Here's my try #6
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
|
@twosevenzero, good call on the duplication. I refactored a bit and added a bit of comments. Hopefully the tests will be more clear |
|
@gniquil I really liked your solution - very slick! I was just curious about doing the analysis in two phases. It looks like the first phase collects the speeches by line to the speakers, and then the second phase counts the lines and aggregates them all up. Instead of copying over all the lines, it seems like speeches and analyze could be combined in to something like: |
|
@briantemple you are absolutely right! The only reason I did it this way was TDD. I wrote the line parser first to just get an understanding. Then I realized all i need was an inject method. BTW, I think inject might be even better here: def analyze
Nokogiri::XML(contents).css("SPEECH").inject(Hash.new(0)) do |recorder, speech|
recorder[speech.at_css("SPEAKER").content] += speech.css("LINE").count
recorder
end
endWow, didn't know Hash.new(0) is so cool! Learned something new today! Thanks! |
lib/macbeth_analyzer.rb
Outdated
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 this block is nicely done. You've made what's happening here extremely clear.
|
Hi All, I guess I am over-thinking too much. Anyway, check out the Hope you guys like it. Frank |
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.
What about pulling this into a named constant?
|
Good effort! See my comments inline. |
|
@r00k Yoda at work! Thanks Ben for the reply. Your comment on the stub is really valuable. The way I was testing it always leaves me a funny uneasy feeling. I will try the responsibility-double approach. |
No description provided.