class YoyakutoptenScraper::App
Attributes
bonus_id[R]
bonus_url[R]
current_reserved[R]
description[R]
icon[R]
max_reserved[R]
publisher[R]
release[R]
screenshot_urls[R]
title[R]
video_url[R]
website_url[R]
Public Class Methods
new(app_id:, os_type:)
click to toggle source
# File lib/yoyakutopten_scraper/app.rb, line 5 def initialize(app_id:, os_type:) @app_id = app_id @os_type = os_type end
Public Instance Methods
parse(html)
click to toggle source
# File lib/yoyakutopten_scraper/app.rb, line 10 def parse(html) detail = (html.css '.app_detail_box').first icon = (detail.css '.app_detail_img').first title = (detail.css 'h1').first publisher = (detail.css '.app_company').first release = ((detail.css '.app_released').first.css 'dd').last reservation = (detail.css '.app_booking').first current_reserved = (reservation.css 'li')[1] max_reserved = (reservation.css 'li')[2] video = (html.css '.app_detail_movie').first unless video.nil? video_frame = (video.css 'iframe').first video_url = video_frame.get_attribute 'src' end screenshot_container = (html.css '.gallery_wrap').first screenshots = screenshot_container.css '.item' screenshot_urls = screenshots.map do |ss| rel_url = (ss.css 'img').first.get_attribute 'src' YoyakutoptenScraper.make_absolute_url rel_url end description = (html.css '.app_description').first bonus_detail = (html.css '.bonus_detail').first unless bonus_detail.nil? bonus = ((bonus_detail.css '.btn_bounus').first.css 'a').first bonus_rel_url = bonus.get_attribute 'href' bonus_rel_url.match %r!/[a-zA-Z]+/[a-zA-Z]+/(\w+)! bonus_url = YoyakutoptenScraper.make_absolute_url bonus_rel_url bonus_id = $1 else bonus_id = '' bonus_url = '' end @title = title.text @icon = (YoyakutoptenScraper.make_absolute_url (icon.get_attribute 'src')) @publisher = publisher.text @release = release.text @current_reserved = current_reserved.text @max_reserved = max_reserved.text @screenshot_urls = screenshot_urls @description = description.to_html @video_url = video_url @bonus_id = bonus_id @bonus_url = (YoyakutoptenScraper.make_absolute_url bonus_url) @website_url = (YoyakutoptenScraper.make_absolute_url ("#{YoyakutoptenScraper::PC_PREFIX}/#{@app_id}")) end
update()
click to toggle source
# File lib/yoyakutopten_scraper/app.rb, line 63 def update query = "#{YoyakutoptenScraper::HOST}/#{YoyakutoptenScraper::PC_PREFIX}/#{@app_id}" user_agents = YoyakutoptenScraper::USER_AGENTS[@os_type] request = Typhoeus::Request.new query, method: 'get', headers: {:"User-Agent" => user_agents}, followlocation: true response = request.run self.parse (Nokogiri::HTML.parse response.body) end