Revision 2153,
583 bytes
checked in by daisuke, 14 years ago
(diff) |
add support author tag
|
Rev | Line | |
---|
[1284] | 1 | class NewsParser |
---|
| 2 | attr_reader :item |
---|
| 3 | def initialize src |
---|
| 4 | @item = Hash.new |
---|
| 5 | @src = src |
---|
| 6 | @pos = 0 |
---|
[2153] | 7 | target = /\n<date>|\n<title>|\n<author>|\n<description>|\n<url>/ |
---|
[1284] | 8 | while @pos != @src.length |
---|
| 9 | from = @pos |
---|
| 10 | to = @src.index target, from |
---|
| 11 | if to == nil |
---|
| 12 | @pos = @src.length |
---|
| 13 | if @src[from..@src.length].match /^<([^\s]+)>(.*)/m |
---|
| 14 | @item[$1.downcase] = $2.strip |
---|
| 15 | end |
---|
| 16 | else |
---|
| 17 | @pos = to + 1 |
---|
| 18 | if @src[from..to].match /^<([^\s]+)>\n(.*)/m |
---|
| 19 | @item[$1.downcase] = $2.strip |
---|
| 20 | end |
---|
| 21 | end |
---|
| 22 | end |
---|
| 23 | end |
---|
| 24 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.