Class: Panchira::Narou::NcodeResolver
- 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
-
#initialize(url, options = nil) ⇒ NcodeResolver
constructor
A new instance of NcodeResolver.
- #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) ⇒ 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, = 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
#parse_author ⇒ Object
63 64 65 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 63 def @desc&.xpath('//*[@id="noveltable1"]/tr[2]/td')&.text&.strip end |
#parse_canonical_url ⇒ Object
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_description ⇒ Object
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_tags ⇒ Object
67 68 69 70 |
# File 'lib/panchira/resolvers/narou_resolver.rb', line 67 def # めっちゃつらい。 @desc&.xpath('//*[@id="noveltable1"]/tr[3]')&.text&.split("\n\n\n")&.dig(1)&.delete("\u00A0")&.split(' ')&.grep_v('') end |