Rev | Line | |
---|
[7253] | 1 | # -*- encoding: utf-8 -*- |
---|
[1284] | 2 | class NewsParser |
---|
| 3 | attr_reader :item |
---|
| 4 | def initialize src |
---|
| 5 | @item = Hash.new |
---|
| 6 | @src = src |
---|
| 7 | @pos = 0 |
---|
[3129] | 8 | target = /\n<date>|\n<title>|\n<author>|\n<description>|\n<url>|\n<target>|\n<info>|\n<directory>|\n<update>/ |
---|
[1284] | 9 | while @pos != @src.length |
---|
| 10 | from = @pos |
---|
| 11 | to = @src.index target, from |
---|
| 12 | if to == nil |
---|
| 13 | @pos = @src.length |
---|
| 14 | if @src[from..@src.length].match /^<([^\s]+)>(.*)/m |
---|
| 15 | @item[$1.downcase] = $2.strip |
---|
| 16 | end |
---|
| 17 | else |
---|
| 18 | @pos = to + 1 |
---|
| 19 | if @src[from..to].match /^<([^\s]+)>\n(.*)/m |
---|
| 20 | @item[$1.downcase] = $2.strip |
---|
| 21 | end |
---|
| 22 | end |
---|
| 23 | end |
---|
| 24 | end |
---|
| 25 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.