Class: Nicovideo::Search

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

Direct Known Subclasses

TagSearch

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, keyword, sort = nil, order = nil, pagenum = 1) ⇒ Search

Returns a new instance of Search.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nicovideo/search.rb', line 7

def initialize agent, keyword, sort=nil, order=nil, pagenum=1
  super(agent)
  @search_type = 'search'
  #@keyword = CGI.escape(CGI.escape(keyword))
  @keyword = CGI.escape(keyword)
  @sort    = sort
  @order   = order
  @pagenum = pagenum

  params = ["videos", "total_size", "has_next?", "has_prev?"]
  self.register_getter params

  @url = url()

  puts_info "url = #{@url}"
  puts_info "sort=#{@sort},order=#{@order},pagenum=#{@pagenum}"
end

Instance Method Details

#eachObject



34
35
36
37
38
# File 'lib/nicovideo/search.rb', line 34

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

#nextObject



54
55
56
57
# File 'lib/nicovideo/search.rb', line 54

def next
  self.pagenum = @pagenum + 1
  self
end

#page=(pagenum) ⇒ Object



50
51
52
# File 'lib/nicovideo/search.rb', line 50

def page=(pagenum)
  self.pagenum = pagenum
end

#pagenum=(pagenum) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/nicovideo/search.rb', line 42

def pagenum=(pagenum)
  if @pagenum != pagenum
    @pagenum = pagenum
    get_page(self.url, true)
  end
  @pagenum
end

#prevObject



59
60
61
62
# File 'lib/nicovideo/search.rb', line 59

def prev
  self.pagenum = @pagenum - 1
  self
end

#to_aObject



40
# File 'lib/nicovideo/search.rb', line 40

def to_a() self.videos end

#urlObject



25
26
27
28
29
30
31
32
# File 'lib/nicovideo/search.rb', line 25

def url
  url = "#{BASE_URL}/#{@search_type}/#{@keyword}"
  url += '?' if (@sort || @order || @pagenum)
  url += '&sort='  + @sort  if @sort
  url += '&order=' + @order if @order
  url += '&page=' + @pagenum.to_s if @pagenum
  url
end