class Nicos::Searcher::ByTagHtml

Attributes

waitConfig[RW]

Public Class Methods

new() click to toggle source
# File lib/classes/searcher.rb, line 93
def initialize
  @numOfSearched = 32
  @incrAmt = 0.2

  @connector = Nicos::Connector.new(:mech)

  # HTML中の各パラメータの所在を示すXPath
  @videoIdXP  = "//div[@class='uad_thumbfrm']/table/tr/td/p/a"
  @lengthXP   = "//div[@class='uad_thumbfrm']/table/tr/td/p[2]/span"
  @viewXP     = "//div[@class='uad_thumbfrm']/table/tr/td[2]/div/nobr[1]/strong"
  @resXP      = "//div[@class='uad_thumbfrm']/table/tr/td[2]/div/nobr[2]/strong"
  @mylistXP   = "//div[@class='uad_thumbfrm']/table/tr/td[2]/div/nobr[3]/a/strong"
  @adXP       = "//div[@class='uad_thumbfrm']/table/tr/td[2]/div/nobr[4]/a/strong"
  @waitConfig = @@waitConfig
end

Public Instance Methods

execute(tag, sortMethod, &block) click to toggle source

@param [String] tag @param [String] sortMethod @param [HashObj] waitConfig

# File lib/classes/searcher.rb, line 142
def execute(tag, sortMethod, &block)
  loop(tag, sort, :mech) { |result, page|
    block.call(result, page)
  }
end

Private Instance Methods

parse(movieNum) click to toggle source
# File lib/classes/searcher.rb, line 112
def parse(movieNum)
  result = []

  video_id  = /(sm|nm)[0-9]{1,}/.match(@connector.mech.page.search(@videoIdXP)[movieNum]['href'])[0]
    lengthStr = @connector.mech.page.search(@lengthXP)[movieNum].text.split(/\:/)
  length    = lengthStr[0].to_i * 60 + lengthStr[1].to_i
  view      = @connector.mech.page.search(@viewXP)[movieNum]
              .text.gsub(/\,/, '').to_i
  res       = @connector.mech.page.search(@resXP)[movieNum]
              .text.gsub(/\,/, '').to_i
  mylist    = @connector.mech.page.search(@mylistXP)[movieNum]
              .text.gsub(/\,/, '').to_i
  ad        = @connector.mech.page.search(@adXP)[movieNum]
              .text.gsub(/\,/, '').to_i

  result.push({
    :video_id => video_id,
    :length   => length,
    :view     => view,
    :res      => res,
    :mylist   => mylist,
    :ad       => ad
  })
end