Class: Panchira::Narou::Novel18Resolver
- Defined in:
- lib/panchira/resolvers/narou_resolver.rb
Constant Summary collapse
- URL_REGEXP =
/novel18\.syosetu\.com\//.freeze
- ID_REGEXP =
%{novel18\.syosetu\.com/(?<id>[^/]+)}
Instance Method Summary collapse
- #fetch_page(uri) ⇒ Object
-
#initialize(url, options = nil) ⇒ Novel18Resolver
constructor
A new instance of Novel18Resolver.
- #parse_author ⇒ Object
-
#parse_canonical_url ⇒ Object
og:urlで指定されたncode.syosetu.com/~~~にアクセスすると301で戻されるので何もしない.
- #parse_description ⇒ Object
- #parse_tags ⇒ Object
Methods inherited from Resolver
Constructor Details
#initialize(url, options = nil) ⇒ Novel18Resolver
Returns a new instance of Novel18Resolver.
11 12 13 14 15 16 17 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 11 def initialize(url, = nil) super(url, ) if id = @url.match(ID_REGEXP)[:id] @desc = fetch_page("https://novel18.syosetu.com/novelview/infotop/ncode/#{id}/") end end |
Instance Method Details
#fetch_page(uri) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 19 def fetch_page(uri) u = URI.parse(uri) http = Net::HTTP.new(u.host, u.port) http.use_ssl = u.port == 443 res = http.get u.request_uri, {'cookie' => 'over18=yes;'} Nokogiri::HTML.parse(res.body, uri) end |
#parse_author ⇒ Object
32 33 34 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 32 def @desc&.xpath('//*[@id="noveltable1"]/tr[2]/td')&.text&.strip end |
#parse_canonical_url ⇒ Object
og:urlで指定されたncode.syosetu.com/~~~にアクセスすると301で戻されるので何もしない
42 43 44 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 42 def parse_canonical_url @url end |
#parse_description ⇒ Object
28 29 30 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 28 def parse_description @desc&.xpath('//*[@id="noveltable1"]/tr/td')&.first&.text&.strip end |
#parse_tags ⇒ Object
36 37 38 39 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 36 def # つらい。 @desc&.xpath('//*[@id="noveltable1"]/tr[3]')&.text&.split("\n\n\n")&.dig(1)&.split(' ') end |