Created
November 4, 2016 03:02
-
-
Save anonymous/6a5782c1eee9b5ee694b5885e7764cb5 to your computer and use it in GitHub Desktop.
Is there good reason for preferring one over the other? My thought was that I might not want to expose the :parser - in that case, would it be correct to mark attr_reader :parser private?
This file contains 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
~/D/u/r/analyzing-shakespeare ❯❯❯ gd ⏎ master ⬆ ✭ ✱ | |
diff --git a/lib/macbeth_analyzer.rb b/lib/macbeth_analyzer.rb | |
index 32b7659..78ac6c4 100644 | |
--- a/lib/macbeth_analyzer.rb | |
+++ b/lib/macbeth_analyzer.rb | |
@@ -4,7 +4,7 @@ require_relative 'xml_parser' | |
require_relative 'printer' | |
class MacbethAnalyzer | |
- attr_reader :speaker_line_counts | |
+ attr_reader :speaker_line_counts, :parser | |
MACBETH_URL = "http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml" | |
IGNORE_SPEAKERS = %w(ALL) | |
@@ -16,7 +16,7 @@ class MacbethAnalyzer | |
def analyze_speaker_line_counts | |
speaker_line_counts = Hash.new(0) | |
- speakers = @parser.parse(query: '//SPEAKER') | |
+ speakers = parser.parse(query: '//SPEAKER') | |
speakers.map do |speaker| | |
unless IGNORE_SPEAKERS.include? speaker.text | |
speaker_line_counts[speaker.text] += @parser.parse( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment