Class: DMMCrawler::Ranking::DojinRanking

Inherits:
BaseRanking show all
Includes:
Attributes
Defined in:
lib/dmm-crawler/ranking/dojin_ranking.rb

Constant Summary collapse

FETCHING_LIMITATION =
10

Instance Method Summary collapse

Constructor Details

#initialize(agent:, submedia: nil, term: nil) ⇒ DojinRanking

Returns a new instance of DojinRanking.



10
11
12
13
14
15
# File 'lib/dmm-crawler/ranking/dojin_ranking.rb', line 10

def initialize(agent:, submedia: nil, term: nil)
  @agent = discriminate_agent(agent)
  @submedia = submedia
  @term = term
  @url = File.join(BASE_URL, "/dc/doujin/-/ranking-all/=/sort=popular/submedia=#{@submedia}/term=#{@term}")
end

Instance Method Details

#artsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dmm-crawler/ranking/dojin_ranking.rb', line 17

def arts
  arts = page.search('.rank-rankListItem.fn-setPurchaseChange').take(FETCHING_LIMITATION).map do |element|
    sleep_each do
      url = File.join(BASE_URL, element.search('.rank-name a').first.attributes['href'].value)
      DojinAttributes.new(url, agent: @agent).to_a
    end
  end

  arts.map.with_index(1) do |(title, title_link, image_url, submedia, author, price, affiliateable, tags), rank|
    {
      title: title,
      title_link: title_link,
      image_url: image_url,
      submedia: submedia,
      author: author,
      rank: rank,
      price: price,
      affiliateable: affiliateable,
      tags: tags
    }
  end
end