Skip to content

Conversation

@mrhead
Copy link

@mrhead mrhead commented Sep 13, 2013

I am afraid that I am not able to do more refactoring, so here is my pull request.

* 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

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?

Copy link
Author

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.

Copy link
Author

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

Copy link
Author

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
@JESii
Copy link

JESii commented Sep 15, 2013

Hi, Patrik... Nice work! You might want to consider updating the output so that the names aren't upper-cased.

Copy link

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.

@mrhead
Copy link
Author

mrhead commented Sep 24, 2013

@andyw8 thanks for all your comments. They all seems valid to me and I will keep them in mind for my next projects. Thanks!

Copy link
Contributor

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

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants