Page
This class doesn't access NICONICO DOUGA when an instance created. At the first time you call this instance method, this accesses NICONICO
# File lib/nicovideo/openlist.rb, line 10 def initialize agent, video_id, sort='c', order='d', pagenum=1 super(agent) @video_id = video_id @pagenum = pagenum @sort = sort @order = order @url = url() params = ["mylists", "total_size", "has_next?", "has_prev?"] self.register_getter params end
# File lib/nicovideo/openlist.rb, line 31 def each self.mylists.each {|ml| yield ml } end
# File lib/nicovideo/openlist.rb, line 52 def next self.pagenum = @pagenum + 1 self end
# File lib/nicovideo/openlist.rb, line 47 def page=(pagenum) self.pagenum = pagenum self end
# File lib/nicovideo/openlist.rb, line 39 def pagenum=(pagenum) if @pagenum != pagenum @pagenum = pagenum get_page(self.url, true) end @pagenum end
# File lib/nicovideo/openlist.rb, line 63 def parse(page) if page.body =~ /<strong.*?>#{@video_id}<\/strong> を登録している公開マイリストはありません。/ @not_found = true raise NotFound end @total_size = page.search('//div[@class="mb8p4"]//p[@class="TXT12"]//strong').first.inner_html.sub(/,/,'').to_i @has_next = false @has_prev = false respages = page/'//div[@class="pagelink"]' puts_info respages.size respages.each {|r| puts_info r.inner_html } if respages.size > 0 respages.each {|text| if text.inner_html =~ /<a class="prevpage".*?>.*?戻る.*?<\/a>/ @has_prev = true end if text.inner_html =~ /<a class="nextpage".*?>.*?進む.*?<\/a>/ @has_next = true end } end scanpattern = /<a href=\"#{BASE_URL}\/mylist\/(\d+)\">(.+?)<\/a>/u listrefs = page.parser.to_html.scan(scanpattern) @mylists = listrefs.inject([]) {|arr, v| # v[0]: mylist id, v[1]: mylist title ml = MyList.new(@agent, v[0]) ml.title = v[1] arr << ml } end
Generated with the Darkfish Rdoc Generator 2.