Class: DMMCrawler::Ranking

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

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Ranking

Returns a new instance of Ranking.



3
4
5
6
7
8
# File 'lib/dmm-crawler/ranking.rb', line 3

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

Instance Method Details

#artsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dmm-crawler/ranking.rb', line 10

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

  arts.map.with_index(1) do |(title, title_link, image_url, submedia, author, informations, tags), rank|
    {
      title: "#{rank}位: #{title}",
      title_link: title_link,
      image_url: image_url,
      submedia: submedia,
      author: author,
      informations: informations,
      tags: tags
    }
  end
end