Class: RandomShakespeare::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/random_shakespeare/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
# File 'lib/random_shakespeare/parser.rb', line 6

def initialize(filename)
  file = get_file(filename)
  @doc = Nokogiri::XML(file)
end

Instance Method Details

#all_linesObject



11
12
13
14
# File 'lib/random_shakespeare/parser.rb', line 11

def all_lines
  return @all_lines if doc_parsed?
  @all_lines = parse_doc
end

#lines_by_speaker(speaker) ⇒ Object



20
21
22
# File 'lib/random_shakespeare/parser.rb', line 20

def lines_by_speaker(speaker)
  all_lines[speaker.titleize]
end

#speakersObject



24
25
26
# File 'lib/random_shakespeare/parser.rb', line 24

def speakers
  all_lines.keys
end

#total_linesObject



16
17
18
# File 'lib/random_shakespeare/parser.rb', line 16

def total_lines
  all_lines.values.flatten.count
end