Class: DmozSax::ContentDocument

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContentDocument

Returns a new instance of ContentDocument.



9
10
11
12
13
14
# File 'lib/dmoz_sax/content_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/content_document.rb', line 7

def name_parser
  @name_parser
end

#on_external_pageObject

Returns the value of attribute on_external_page.



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

def on_external_page
  @on_external_page
end

#on_topicObject

Returns the value of attribute on_topic.



6
7
8
# File 'lib/dmoz_sax/content_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/content_document.rb', line 7

def time_parser
  @time_parser
end

Instance Method Details

#characters(string) ⇒ Object



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

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

#end_element(name) ⇒ Object



37
38
39
40
41
42
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/content_document.rb', line 37

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 'Topic'
    @topic.cid = @cid
    @on_topic.call(@topic) unless @on_topic.nil?
  when 'topic'
    @path = DmozSax::Path.new @buffer
  when 'mediadate'
    @time = @time_parser.time_from @buffer
  when 'priority'
    @priority = @buffer.to_i
  when 'ExternalPage'
    @external.priority = @priority
    @external.title = @title
    @external.description = @description
    @external.path = @path
    @external.time = @time
    @on_external_page.call(@external) unless @on_external_page.nil?
  end
end

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dmoz_sax/content_document.rb', line 21

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

  case name 
  when 'Topic'
    @topic = DmozSax::Topic.new attributes[0][1]
  when /^link/
    @topic.links << attributes[0][1]
  when 'ExternalPage'
    @priority = 0
    @time = nil
    @external = DmozSax::ExternalPage.new attributes[0][1]
  end
end