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.
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.
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.