class Recent attr_accessor:grp_name,:channel,:items
def initialize(grp_name,count) @grp_name=grp_name @url="http://www.hemidemi.com/rss/group/#{@grp_name}/bookmark/recent.xml" @channel=@channel||{} @items=[] ifcount==nil @count=6 else @count=count.to_i end end
def run load_in show end def load_in open(@url)do|f| xml=Document.new(f.read)
xml.elements.each("*/channel")do|chnl| @channel["name"]=chnl.elements["description"].text @channel["link"]=chnl.elements["link"].text end
xml.elements.each("*/channel/item")do|item| itm={} itm["title"]=item.elements["title"].text itm["description"]=item.elements["description"].text itm["link"]=item.elements["link"].text itm["creator"]=item.elements["dc:creator"].text @items<<itm end end end
def show puts"="*10 puts"群組:#{@channel["name"]} [ #{@channel["link"]} ]" puts"共有#{@items.size}個書籤" puts"="*10 @count=@items.sizeif@items.size<@count @count.times{|cnt| puts"張貼者:#{@items[cnt]["creator"]} [ http://www.hemidemi.com/user/#{@items[cnt]["creator"]}/home ]" puts"標題:#{@items[cnt]["title"]}" puts"網址:#{@items[cnt]["link"]}" puts"敘述:#{@items[cnt]["description"]}" puts"*"*10 } puts"="*10 end public:run private:load_in,:show end