Class: DmozSax::StructureDocument

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/dmoz_sax/structure_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStructureDocument

Returns a new instance of StructureDocument.



9
10
11
12
13
14
# File 'lib/dmoz_sax/structure_document.rb', line 9

def initialize
  super

  @name_parser = NameParser.new
  @time_parser = TimeParser.new
end

Instance Attribute Details

#name_parserObject

Returns the value of attribute name_parser.



7
8
9
# File 'lib/dmoz_sax/structure_document.rb', line 7

def name_parser
  @name_parser
end

#on_aliasObject

Returns the value of attribute on_alias.



6
7
8
# File 'lib/dmoz_sax/structure_document.rb', line 6

def on_alias
  @on_alias
end

#on_topicObject

Returns the value of attribute on_topic.



6
7
8
# File 'lib/dmoz_sax/structure_document.rb', line 6

def on_topic
  @on_topic
end

#time_parserObject

Returns the value of attribute time_parser.



7
8
9
# File 'lib/dmoz_sax/structure_document.rb', line 7

def time_parser
  @time_parser
end

Instance Method Details

#characters(string) ⇒ Object



16
17
18
19
# File 'lib/dmoz_sax/structure_document.rb', line 16

def characters string
  @buffer ||= ""
  @buffer << string
end

#end_element(name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dmoz_sax/structure_document.rb', line 43

def end_element name

  case name
  when 'catid'
    @cid = @buffer.to_i
  when 'd:Description'
    @description = @buffer.strip
  when 'd:Title'
    @title = @buffer.strip.gsub('_', ' ')
  when 'lastUpdate'
    @time = @time_parser.time_from @buffer
  when 'Alias'
    @on_alias.call(@alias) unless @on_alias.nil?
  when 'Topic'
    @topic.cid = @cid
    @topic.title = @title
    @topic.description = @description
    @topic.time = @time
    @on_topic.call(@topic) unless @on_topic.nil?
  end
end

#start_element(name, attributes = []) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dmoz_sax/structure_document.rb', line 21

def start_element name, attributes = []
  @buffer = ""

  case name
  when 'Topic'
    @cid, @description, @title = nil, nil, nil
    @topic = DmozSax::Topic.new attributes[0][1]
  when 'Alias'
    @alias = DmozSax::Alias.new attributes[0][1]
  when 'Target'
    @path = attributes[0][1]
  when 'altlang'
    @topic.alt_langs << DmozSax::Path.new(attributes[0][1])
  when 'related'
    @topic.related << DmozSax::Path.new(attributes[0][1])
  when /^narrow/
    @topic.narrows << DmozSax::Path.new(attributes[0][1], @name_parser.level_from(name))
  when /^symbolic/
    @topic.symbolics << DmozSax::Path.new(attributes[0][1], @name_parser.level_from(name))
  end
end