Analyzer attempt by Dave West (@twosevenero)#2
Analyzer attempt by Dave West (@twosevenero)#2twosevenzero wants to merge 6 commits intothoughtbot:masterfrom twosevenzero:twosevenzero
Conversation
lib/shakespeare_analyzer.rb
Outdated
There was a problem hiding this comment.
What about making this url a named constant instead?
There was a problem hiding this comment.
so something like MACBETH = then
def initialize url = MACBETH
For readability sake or is there another reason?
There was a problem hiding this comment.
Mostly readability, but also because it helps you avoid the temptation to duplicate this string elsewhere (which you actually ended up doing).
|
Good work! Left a bunch of comments. |
lib/shakespeare_analyzer.rb
Outdated
There was a problem hiding this comment.
@twosevenzero There is a bug in your code because it is not able to correctly count speakers in this case:
# hamlet.xml
<SPEECH>
<SPEAKER>CORNELIUS</SPEAKER>
<SPEAKER>VOLTIMAND</SPEAKER>
<LINE>In that and all things will we show our duty.</LINE>
</SPEECH>
I've found it by accident by comparing yours and my results. Your code cannot detect CORNELIUS. However I did not check if there are such SPEECHes in Macbeth.
|
just found same SPEECH in Macbeth: @r00k How we should count it? One line for each? |
|
Awesome find! Thanks @mrhead |
There was a problem hiding this comment.
Perhaps these two blocks could be combined, since @characters is not used outside this block?
speech.elements.each("SPEAKER") do |speaker|
@speakers[speaker] += @line_count
end
There was a problem hiding this comment.
By the way, [] is equivalent to Array.new and seems be more idiomatic.
|
Nice solution -- I had not seen the rexml library before. Pretty slick! |
There was a problem hiding this comment.
I like that you clear split out the four separate steps required. One suggestion I would make is to extract the first line into it's own method, named something like read_text_file. Each method call in the start would then be at the same level of abstraction, which I think would make things more readable.
There was a problem hiding this comment.
Awesome. Thanks for the feedback!
This was just what I needed to get a grasp on TDD. Thank you!