Class: Datasets::Wikipedia::ArticlesListener
- Inherits:
-
Object
- Object
- Datasets::Wikipedia::ArticlesListener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/datasets/wikipedia.rb
Instance Method Summary collapse
- #cdata(content) ⇒ Object
-
#initialize(block) ⇒ ArticlesListener
constructor
A new instance of ArticlesListener.
- #tag_end(name) ⇒ Object
- #tag_start(name, attributes) ⇒ Object
- #text(data) ⇒ Object
Constructor Details
#initialize(block) ⇒ ArticlesListener
Returns a new instance of ArticlesListener.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/datasets/wikipedia.rb', line 77 def initialize(block) @block = block @page = nil @revision = nil @contributor = nil @current_tag = nil @tag_stack = [] @text_stack = [""] @first_page = true end |
Instance Method Details
#cdata(content) ⇒ Object
155 156 157 |
# File 'lib/datasets/wikipedia.rb', line 155 def cdata(content) @text_stack.last << content end |
#tag_end(name) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/datasets/wikipedia.rb', line 102 def tag_end(name) case name when "page" on_page(@page) @page = nil when "title" @page.title = @text_stack.last when "ns" @page.namespace = Integer(@text_stack.last) when "id" id = Integer(@text_stack.last) case @tag_stack[-2] when "page" @page.id = id when "revision" @revision.id = id when "contributor" @contributor.id = id end when "restrictions" @page.restrictions = @text_stack.last.split(":") when "revision" @page.revision = @revision @revision = nil when "parentid" @revision.parent_id = Integer(@text_stack.last) when "timestamp" @revision. = Time.iso8601(@text_stack.last) when "contributor" @revision.contributor = @contributor @contributor = nil when "username" @contributor.user_name = @text_stack.last when "minor" # TODO when "comment" @revision.comment = @text_stack.last when "model" @revision.model = @text_stack.last when "format" @revision.format = @text_stack.last when "text" @revision.text = @text_stack.last when "sha1" @revision.sha1 = @text_stack.last end pop_stacks end |
#tag_start(name, attributes) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/datasets/wikipedia.rb', line 88 def tag_start(name, attributes) push_stacks(name) case name when "page" @page = Page.new when "revision" @revision = Revision.new when "contributor" @contributor = Contributor.new when "redirect" @page.redirect = attributes["title"] end end |
#text(data) ⇒ Object
151 152 153 |
# File 'lib/datasets/wikipedia.rb', line 151 def text(data) @text_stack.last << data end |