source: projects/web/trunk/bin/newsparser.rb @ 7253

Revision 7253, 654 bytes checked in by daisuke, 11 years ago (diff)

update code

Line 
1# -*- encoding: utf-8 -*-
2class NewsParser
3  attr_reader :item
4  def initialize src
5    @item = Hash.new
6    @src = src
7    @pos = 0
8    target = /\n<date>|\n<title>|\n<author>|\n<description>|\n<url>|\n<target>|\n<info>|\n<directory>|\n<update>/
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
25end
Note: See TracBrowser for help on using the repository browser.