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.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/datasets/wikipedia.rb', line 86 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
164 165 166 |
# File 'lib/datasets/wikipedia.rb', line 164 def cdata(content) @text_stack.last << content end |
#tag_end(name) ⇒ Object
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 150 151 152 153 154 155 156 157 158 |
# File 'lib/datasets/wikipedia.rb', line 111 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
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/datasets/wikipedia.rb', line 97 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
160 161 162 |
# File 'lib/datasets/wikipedia.rb', line 160 def text(data) @text_stack.last << data end |