Class: Tag
- Inherits:
-
Object
- Object
- Tag
- Defined in:
- lib/nhentai-api.rb
Class Method Summary collapse
-
.listing(keyword, sort = 1, page = 1) ⇒ Array
List all doujinshi of the page of a given tag.
- .parse_tags(res) ⇒ Object
Class Method Details
.listing(keyword, sort = 1, page = 1) ⇒ Array
List all doujinshi of the page of a given tag
428 429 430 431 432 433 434 435 |
# File 'lib/nhentai-api.rb', line 428 def self.listing(keyword, sort = 1, page = 1) keyword.tr!(' ', '-') sort = sort == 1 ? '' : 'popular' client = Net::HTTP.get_response(URI("https://nhentai.net/tag/#{keyword}/#{sort}?page=#{page}")) res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') } (res) end |
.parse_tags(res) ⇒ Object
440 441 442 443 444 445 446 447 448 449 |
# File 'lib/nhentai-api.rb', line 440 def self.(res) res.map do |line| id = line.match(%r{/g/(\d+)/})[1] name = line.match(%r{<div class="caption">(.+)</div>})[1].strip count = 1 url = "/g/#{id}" Info.new(id, name, count, url) end end |