-
-
Notifications
You must be signed in to change notification settings - Fork 50
Analyzer attempt by Dave West (@twosevenero) #2
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
lib/shakespeare_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.
What about making this url a named constant instead?
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.
so something like MACBETH = then
def initialize url = MACBETH
For readability sake or is there another reason?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks for the feedback!
This was just what I needed to get a grasp on TDD. Thank you!