class Panchira::MelonbooksResolver
Constants
- URL_REGEXP
Public Instance Methods
fetch()
click to toggle source
# File lib/panchira/resolvers/melonbooks_resolver.rb, line 7 def fetch result = PanchiraResult.new @page = fetch_page(@url) result.canonical_url = parse_canonical_url @page = fetch_page(result.canonical_url) if @url != result.canonical_url result.title, result.author, result.circle = parse_table result.description = parse_description result.image = parse_image result.tags = parse_tags result.resolver = parse_resolver result end
Private Instance Methods
parse_canonical_url()
click to toggle source
# File lib/panchira/resolvers/melonbooks_resolver.rb, line 43 def parse_canonical_url product_id = @url.slice(URL_REGEXP, 1) "https://www.melonbooks.co.jp/detail/detail.php?product_id=#{product_id}&adult_view=1" end
parse_description()
click to toggle source
# File lib/panchira/resolvers/melonbooks_resolver.rb, line 48 def parse_description # スタッフの紹介文でidが分岐 special_description = @page.xpath('//div[@id="special_description"]//p/text()') if special_description.any? special_description.first.to_s else description = @page.xpath('//div[@id="description"]//p/text()') description.first.to_s end end
parse_image_url()
click to toggle source
# File lib/panchira/resolvers/melonbooks_resolver.rb, line 59 def parse_image_url @page.css('//meta[property="og:image"]/@content').first.to_s.sub(/&c=1/, '') end
parse_table()
click to toggle source
# File lib/panchira/resolvers/melonbooks_resolver.rb, line 26 def parse_table title, author, circle = nil, nil, nil @page.css('#description > table.stripe > tr').each do |tr| case tr.css('th').text when 'タイトル' title = tr.css('td').text.strip when 'サークル名' circle = tr.css('td > a').text.match(/^(.+)\W\(作品数:/)&.values_at(1)&.first when '作家名' author = tr.css('td > a').text.strip end end [title, author, circle] end