Class: DMMCrawler::Ranking::AdultGameRanking

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

Constant Summary collapse

FETCHING_LIMITATION =
20
DLSOFT_URL =
'https://dlsoft.dmm.co.jp/'

Instance Method Summary collapse

Constructor Details

#initialize(agent: Agent.instance.agent, term: nil) ⇒ AdultGameRanking

Returns a new instance of AdultGameRanking.



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

def initialize(agent: Agent.instance.agent, term: nil)
  @agent = discriminate_agent(agent)
  @term = term
  @url = URI.join(DLSOFT_URL, File.join('ranking', parameterized_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
39
# File 'lib/dmm-crawler/ranking/adult_game_ranking.rb', line 17

def arts
  games = page.search('.rankingList-content .rankingList-item.fn-rankListItem').take(FETCHING_LIMITATION)
  arts = games.map do |game|
    sleep_each do
      url = game.search('.rankingList-link').first.attributes['href'].value
      AdultGameAttributes.new(url, agent: @agent).to_a
    end
  end

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