Class: Nzb::Parser::Callbacks

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks
Defined in:
lib/nzb/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



21
22
23
# File 'lib/nzb/parser.rb', line 21

def initialize
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



19
20
21
# File 'lib/nzb/parser.rb', line 19

def files
  @files
end

Instance Method Details

#on_characters(text) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/nzb/parser.rb', line 36

def on_characters(text)
  if @segment
    @segment.msgid = text.strip
    @segment = nil
  elsif @group
    @files.last.add_group(text.strip)
    @group = nil
  end
end

#on_start_element(name, attrs) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/nzb/parser.rb', line 25

def on_start_element(name, attrs)
  case name
  when "file"
    @files << File.new(attrs)
  when "segment"
    @segment = @files.last.add_segment(attrs)
  when "group"
    @group = true
  end
end