-
-
Notifications
You must be signed in to change notification settings - Fork 50
Attempt by Patrik Bóna #3
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
* create Gemfile and add rspec gem * create empty spec dir * set some default options in .rspec
* URI content is stored in @file_content
* with speaker method in XmlParser object
Declared PERSONAS don't mach SPEAKER in SPEECHEs, for example <PERSONA>Three Witches.</PERSONA> vs. <SPEAKER>First Witch</SPEAKER> ... whole xml: http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml
* run it with `ruby lib/shakespeare_analyzer.rb`
* refactor `speakers` method to one line * rename `lines_by_speaker` to `count_lines_by_speaker`
Almost all methods are now one line long.
output.txt
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.
Even after fixing the bug in my code, I am not getting a number this high for Macbeth. Do we know what the actual answer is?
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.
Well I do not know what are the correct numbers ;).
I perform my tests on small test.xml file and for this file everything is calculated correctly. But I do not know if I do not miss some edge cases in XML.
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.
Well I just found bug in my code, I need to fix it. Hopefully then we will have same numbers ;).
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.
Bug fixed, now we have same numbers for Macbeth ;)
`count_lines_by_speaker` is now looking for exact match in speaker's
name.
Example XML:
<SPEECH>
<SPEAKER>A</SPEAKER>
<LINE>Line!</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>AAA</SPEAKER>
<LINE>Line!</LINE>
</SPEECH>
before:
count_lines_by_speaker('A') == 2
now:
count_lines_by_speaker('A') == 1
|
Hi, Patrik... Nice work! You might want to consider updating the output so that the names aren't upper-cased. |
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 it would be good to avoid passing a URL to the initializer, and just provide the data instead. That means you could supply text from a file, and it should also make testing easier.
|
@andyw8 thanks for all your comments. They all seems valid to me and I will keep them in mind for my next projects. Thanks! |
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.
You're one of the only folks to extract this into a constant. I like it. :)
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.
Nice high level of abstraction.
I am afraid that I am not able to do more refactoring, so here is my pull request.