-
-
Notifications
You must be signed in to change notification settings - Fork 50
Here's my try #6
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
Open
gniquil
wants to merge
10
commits into
thoughtbot:master
Choose a base branch
from
gniquil:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5571a35
basically working
gniquil c3cfbad
added output
gniquil 26f9c66
refactored
gniquil 438f56a
refactored to accomodate some changes suggested by @briantemple
gniquil 7cf70e4
added handling of the "ALL" speaker
gniquil 42cb326
renamed misnamed top level file
gniquil 853e5d2
added one step analyze
gniquil 20e13cb
simplified one_step even more
gniquil b0febd9
added handling of multiple speakers within a speech
gniquil 224e127
removed one step and merged into original analyze
gniquil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /tmp | ||
| *.gem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --color |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # A sample Guardfile | ||
| # More info at https://github.com/guard/guard#readme | ||
|
|
||
| guard :rspec, cli: "--tag ~@external" do | ||
| watch(%r{^spec/.+_spec\.rb$}) | ||
| watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
| watch('spec/spec_helper.rb') { "spec" } | ||
| watch(%r{^spec/support/.+\.rb$}) { "spec" } | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| require 'open-uri' | ||
| require "nokogiri" | ||
|
|
||
| class MacbethAnalyzer | ||
| attr_reader :url | ||
|
|
||
| def initialize | ||
| @url = "http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml" | ||
|
|
||
| end | ||
|
|
||
| def contents | ||
| @contents ||= open(url).read | ||
| end | ||
|
|
||
| def analyze | ||
| Nokogiri::XML(contents).xpath("//SPEECH[SPEAKER!='ALL']/LINE").inject(Hash.new(0)) do |recorder, line_node| | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could extract a few small methods here and make this method substantially easier to read. |
||
| line_node.xpath("preceding-sibling::SPEAKER").each do |speaker| | ||
| recorder[speaker.content] += 1 | ||
| end | ||
| recorder | ||
| end | ||
| end | ||
|
|
||
| def output | ||
| analyze.sort_by {|speaker, line_count| -line_count }.map do |speaker, line_count| | ||
| "#{line_count.to_s.rjust(3, " ")} #{speaker}" | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| require_relative 'lib/macbeth_analyzer' | ||
|
|
||
| MacbethAnalyzer.new.output.each {|o| puts o } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 719 MACBETH | ||
| 265 LADY MACBETH | ||
| 212 MALCOLM | ||
| 180 MACDUFF | ||
| 135 ROSS | ||
| 113 BANQUO | ||
| 74 LENNOX | ||
| 70 DUNCAN | ||
| 62 First Witch | ||
| 46 Porter | ||
| 45 Doctor | ||
| 41 LADY MACDUFF | ||
| 39 HECATE | ||
| 35 Sergeant | ||
| 30 SIWARD | ||
| 30 First Murderer | ||
| 27 Second Witch | ||
| 27 Third Witch | ||
| 23 Messenger | ||
| 23 Gentlewoman | ||
| 21 Lord | ||
| 21 ANGUS | ||
| 20 Son | ||
| 15 Second Murderer | ||
| 12 MENTEITH | ||
| 11 Old Man | ||
| 11 CAITHNESS | ||
| 10 DONALBAIN | ||
| 8 Third Murderer | ||
| 7 YOUNG SIWARD | ||
| 5 Servant | ||
| 5 SEYTON | ||
| 5 Third Apparition | ||
| 4 Second Apparition | ||
| 3 Lords | ||
| 2 First Apparition | ||
| 2 Both Murderers | ||
| 2 FLEANCE | ||
| 1 Soldiers | ||
| 1 ATTENDANT |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 pulling this into a named constant?