Class: Nicovideo::Newarrival

Inherits:
Page
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nicovideo/newarrival.rb

Constant Summary

Constants inherited from Page

Page::BASE_TITLE1, Page::BASE_TITLE2, Page::BASE_URL, Page::NV_DEBUG_LEVEL

Instance Method Summary collapse

Methods inherited from Page

#exists?, #html, #title=

Constructor Details

#initialize(agent, pagenum) ⇒ Newarrival

Returns a new instance of Newarrival.



5
6
7
8
9
10
11
12
13
14
# File 'lib/nicovideo/newarrival.rb', line 5

def initialize(agent, pagenum)
  super(agent)

  @pagenum = pagenum > 10 ? 10 : pagenum

  params = ["videos"]
  self.register_getter params

  @url = url()
end

Instance Method Details

#eachObject



25
26
27
# File 'lib/nicovideo/newarrival.rb', line 25

def each
  self.videos.each {|v| yield v }
end

#parse(page) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/nicovideo/newarrival.rb', line 16

def parse(page)
  result_xpath = page/'//div[@class="cmn_thumb_R"]//p[@class="TXT12"]/a[@class="video"]'
  @videos = result_xpath.inject([]) do |arr, v|
    vp = VideoPage.new(@agent, v.attributes['href'].sub(/watch\/(\w+)$/,'\1'))
    vp.title = v.inner_html
    arr << vp
  end
end

#urlObject



29
30
31
32
# File 'lib/nicovideo/newarrival.rb', line 29

def url
  opt = '?page=' + @pagenum.to_s if @pagenum
  "#{BASE_URL}/newarrival#{opt}"
end