Skip to content

Conversation

@twosevenzero
Copy link

This was just what I needed to get a grasp on TDD. Thank you!

Copy link
Contributor

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?

Copy link
Author

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?

Copy link
Contributor

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

@r00k
Copy link
Contributor

r00k commented Sep 13, 2013

Good work!

Left a bunch of comments.

Copy link

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.

@mrhead
Copy link

mrhead commented Sep 13, 2013

just found same SPEECH in Macbeth:

<SPEECH>
<SPEAKER>MACBETH</SPEAKER>
<SPEAKER>LENNOX</SPEAKER>
<LINE>What's the matter.</LINE>
</SPEECH>

@r00k How we should count it? One line for each?

@twosevenzero
Copy link
Author

Awesome find! Thanks @mrhead

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

Copy link

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.

@briantemple
Copy link

Nice solution -- I had not seen the rexml library before. Pretty slick!

Copy link

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.

Copy link
Author

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!

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.

5 participants