Class: Panchira::Narou::NcodeResolver

Inherits:
Resolver
  • Object
show all
Defined in:
lib/panchira/resolvers/narou_resolver.rb

Constant Summary collapse

URL_REGEXP =
/ncode\.syosetu\.com/.freeze
ID_REGEXP =
%{ncode\.syosetu\.com/(?<id>[^/]+)}

Instance Method Summary collapse

Methods inherited from Resolver

applicable?, #fetch

Constructor Details

#initialize(url, options = nil) ⇒ NcodeResolver

Returns a new instance of NcodeResolver.



51
52
53
54
55
56
57
# File 'lib/panchira/resolvers/narou_resolver.rb', line 51

def initialize(url, options = nil)
  super(url, options)

  if id = @url.match(ID_REGEXP)[:id]
    @desc = fetch_page("https://novel18.syosetu.com/novelview/infotop/ncode/#{id}/")
  end
end

Instance Method Details

#parse_authorObject



63
64
65
# File 'lib/panchira/resolvers/narou_resolver.rb', line 63

def parse_author
  @desc&.xpath('//*[@id="noveltable1"]/tr[2]/td')&.text&.strip
end

#parse_canonical_urlObject

og:urlで指定されたncode.syosetu.com/~~~にアクセスすると301で戻されるので何もしない



73
74
75
# File 'lib/panchira/resolvers/narou_resolver.rb', line 73

def parse_canonical_url
  @url
end

#parse_descriptionObject



59
60
61
# File 'lib/panchira/resolvers/narou_resolver.rb', line 59

def parse_description
  @desc&.xpath('//*[@id="noveltable1"]/tr/td')&.first&.text&.strip
end

#parse_tagsObject



67
68
69
70
# File 'lib/panchira/resolvers/narou_resolver.rb', line 67

def parse_tags
  # めっちゃつらい。
  @desc&.xpath('//*[@id="noveltable1"]/tr[3]')&.text&.split("\n\n\n")&.dig(1)&.delete("\u00A0")&.split(' ')&.grep_v('')
end