Class: Doujinshi
- Inherits:
-
Object
- Object
- Doujinshi
- Defined in:
- lib/nhentai-api.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#count_pages ⇒ Object
readonly
Returns the value of attribute count_pages.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#media_id ⇒ Object
readonly
Returns the value of attribute media_id.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #count_favorites ⇒ Object
- #cover ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(id) ⇒ Doujinshi
constructor
A new instance of Doujinshi.
- #page(page = 1) ⇒ Object
- #pages ⇒ Object
- #thumbnail(page = 1) ⇒ Object
- #thumbnails ⇒ Object
- #title ⇒ Object
- #upload_date ⇒ Object
Constructor Details
#initialize(id) ⇒ Doujinshi
Returns a new instance of Doujinshi.
11 12 13 14 15 16 17 18 |
# File 'lib/nhentai-api.rb', line 11 def initialize(id) @id = id @client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/")) return unless exists? @media_id = client.body.match(%r{\/([0-9]+)\/cover})[1] @count_pages = client.body.match(/Pages:\s*.*>([0-9]+)</)[1].to_i end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/nhentai-api.rb', line 9 def client @client end |
#count_pages ⇒ Object (readonly)
Returns the value of attribute count_pages.
9 10 11 |
# File 'lib/nhentai-api.rb', line 9 def count_pages @count_pages end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/nhentai-api.rb', line 9 def id @id end |
#media_id ⇒ Object (readonly)
Returns the value of attribute media_id.
9 10 11 |
# File 'lib/nhentai-api.rb', line 9 def media_id @media_id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/nhentai-api.rb', line 9 def response @response end |
Instance Method Details
#count_favorites ⇒ Object
54 55 56 57 58 |
# File 'lib/nhentai-api.rb', line 54 def count_favorites regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>} client.body.match(regex)[1].to_i end |
#cover ⇒ Object
28 29 30 31 32 |
# File 'lib/nhentai-api.rb', line 28 def cover res = client.body.match(%r{https://t.*.nhentai.net/galleries/#{media_id}/cover\.(.{3})"}) "https://t.nhentai.net/galleries/#{media_id}/cover.#{res[1]}" end |
#exists? ⇒ Boolean
20 21 22 |
# File 'lib/nhentai-api.rb', line 20 def exists? client.code == '200' end |
#page(page = 1) ⇒ Object
34 35 36 37 38 |
# File 'lib/nhentai-api.rb', line 34 def page(page = 1) res = client.body.match(%r{https://t.*.nhentai.net/galleries/#{media_id}/#{page}t\.(.{3})"}) "https://i.nhentai.net/galleries/#{media_id}/#{page}.#{res[1]}" end |
#pages ⇒ Object
40 41 42 |
# File 'lib/nhentai-api.rb', line 40 def pages (1..count_pages).map { |page| page(page) } end |
#thumbnail(page = 1) ⇒ Object
44 45 46 47 48 |
# File 'lib/nhentai-api.rb', line 44 def thumbnail(page = 1) res = client.body.match(%r{https://t.*.nhentai.net/galleries/#{media_id}/(#{page}t\..{3})"}) "https://t.nhentai.net/galleries/#{media_id}/#{res[1]}" end |
#thumbnails ⇒ Object
50 51 52 |
# File 'lib/nhentai-api.rb', line 50 def thumbnails (1..count_pages).map { |page| thumbnail(page) } end |
#title ⇒ Object
24 25 26 |
# File 'lib/nhentai-api.rb', line 24 def title client.body.match(/"pretty">(.*?)</)[1] end |
#upload_date ⇒ Object
60 61 62 |
# File 'lib/nhentai-api.rb', line 60 def upload_date Time.iso8601(client.body.match(/<time .+ datetime="(.*?)"/)[1]) end |