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.
Instance Method Summary collapse
-
#artists ⇒ Object
Give all artists of a doujinshi.
-
#artists? ⇒ Boolean
Check if a particular doujinshi have some artists.
-
#categories ⇒ Object
Give all categories of a doujinshi.
-
#categories? ⇒ Boolean
Check if a particular doujinshi have some categories.
-
#characters ⇒ Object
Give all characters of a doujinshi.
-
#characters? ⇒ Boolean
Check if a particular doujinshi have some characters.
-
#count_artists ⇒ Object
Give a counter of artists.
-
#count_categories ⇒ Object
Give a counter of categories.
-
#count_characters ⇒ Object
Give a counter of characters.
-
#count_favorites ⇒ Integer
Give the number of favorites on a doujinshi.
-
#count_groups ⇒ Object
Give a counter of groups.
-
#count_languages ⇒ Object
Give a counter of languages.
-
#count_parodies ⇒ Object
Give a counter of parodies.
-
#count_tags ⇒ Integer
Give a counter of tags.
-
#cover ⇒ String
Give the cover’s URL of a doujinshi.
-
#exists? ⇒ Bool
Check if a doujinshi with the given id exist.
-
#groups ⇒ Object
Give all groups of a doujinshi.
-
#groups? ⇒ Boolean
Check if a particular doujinshi have some groups.
-
#initialize(id) ⇒ Doujinshi
constructor
A new instance of Doujinshi.
-
#languages ⇒ Object
Give all languages of a doujinshi.
-
#languages? ⇒ Boolean
Check if a particular doujinshi have some languages.
-
#page(page = 1) ⇒ String
Give the URL of a given page of a doujinshi.
-
#pages ⇒ Array
Give the URL of a all pages of a doujinshi.
-
#parodies ⇒ Object
Give all parodies of a doujinshi.
-
#parodies? ⇒ Boolean
Check if a particular doujinshi have some parodies.
-
#tags ⇒ Array
Give all tags of a doujinshi.
-
#tags? ⇒ Bool
Check if a particular doujinshi have some tags.
-
#thumbnail(page = 1) ⇒ String
Give the thumbnail’s URL of a given page of a doujinshi.
-
#thumbnails ⇒ Array
Give the URL of a all thumbnails of a doujinshi.
-
#title ⇒ String
Give the title of a doujinshi.
-
#upload_date ⇒ Integer
Give the upload date of a doujinshi.
Constructor Details
#initialize(id) ⇒ Doujinshi
Returns a new instance of Doujinshi.
18 19 20 21 22 23 24 25 |
# File 'lib/nhentai-api.rb', line 18 def initialize(id) @id = id @client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/")) if self.exists? @media_id = @client.body.match(%r{\/([0-9]+)\/cover})[1] @count_pages = @client.body.match(/Pages:\s*.*>([0-9]+)</)[1].to_i end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/nhentai-api.rb', line 16 def client @client end |
#count_pages ⇒ Object (readonly)
Returns the value of attribute count_pages.
16 17 18 |
# File 'lib/nhentai-api.rb', line 16 def count_pages @count_pages end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/nhentai-api.rb', line 16 def id @id end |
#media_id ⇒ Object (readonly)
Returns the value of attribute media_id.
16 17 18 |
# File 'lib/nhentai-api.rb', line 16 def media_id @media_id end |
Instance Method Details
#artists ⇒ Object
Give all artists of a doujinshi
264 265 266 267 268 269 |
# File 'lib/nhentai-api.rb', line 264 def artists res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#artists? ⇒ Boolean
Check if a particular doujinshi have some artists
289 290 291 |
# File 'lib/nhentai-api.rb', line 289 def artists? !@client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}).nil? end |
#categories ⇒ Object
Give all categories of a doujinshi
369 370 371 372 373 374 |
# File 'lib/nhentai-api.rb', line 369 def categories res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#categories? ⇒ Boolean
Check if a particular doujinshi have some categories
394 395 396 |
# File 'lib/nhentai-api.rb', line 394 def categories? !@client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}).nil? end |
#characters ⇒ Object
Give all characters of a doujinshi
229 230 231 232 233 234 |
# File 'lib/nhentai-api.rb', line 229 def characters res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#characters? ⇒ Boolean
Check if a particular doujinshi have some characters
254 255 256 |
# File 'lib/nhentai-api.rb', line 254 def characters? !@client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}).nil? end |
#count_artists ⇒ Object
Give a counter of artists
277 278 279 280 281 |
# File 'lib/nhentai-api.rb', line 277 def count_artists res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_categories ⇒ Object
Give a counter of categories
382 383 384 385 386 |
# File 'lib/nhentai-api.rb', line 382 def count_categories res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_characters ⇒ Object
Give a counter of characters
242 243 244 245 246 |
# File 'lib/nhentai-api.rb', line 242 def count_characters res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_favorites ⇒ Integer
Give the number of favorites on a doujinshi
129 130 131 132 133 |
# File 'lib/nhentai-api.rb', line 129 def count_favorites regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>} @client.body.match(regex)[1].to_i end |
#count_groups ⇒ Object
Give a counter of groups
312 313 314 315 316 |
# File 'lib/nhentai-api.rb', line 312 def count_groups res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_languages ⇒ Object
Give a counter of languages
347 348 349 350 351 |
# File 'lib/nhentai-api.rb', line 347 def count_languages res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_parodies ⇒ Object
Give a counter of parodies
207 208 209 210 211 |
# File 'lib/nhentai-api.rb', line 207 def count_parodies res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#count_tags ⇒ Integer
Give a counter of tags
170 171 172 173 174 |
# File 'lib/nhentai-api.rb', line 170 def res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>}) res.nil? ? 0 : (res[1]).length end |
#cover ⇒ String
Give the cover’s URL of a doujinshi
59 60 61 62 63 |
# File 'lib/nhentai-api.rb', line 59 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? ⇒ Bool
Check if a doujinshi with the given id exist
35 36 37 |
# File 'lib/nhentai-api.rb', line 35 def exists? @client.code == '200' end |
#groups ⇒ Object
Give all groups of a doujinshi
299 300 301 302 303 304 |
# File 'lib/nhentai-api.rb', line 299 def groups res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#groups? ⇒ Boolean
Check if a particular doujinshi have some groups
324 325 326 |
# File 'lib/nhentai-api.rb', line 324 def groups? !@client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}).nil? end |
#languages ⇒ Object
Give all languages of a doujinshi
334 335 336 337 338 339 |
# File 'lib/nhentai-api.rb', line 334 def languages res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#languages? ⇒ Boolean
Check if a particular doujinshi have some languages
359 360 361 |
# File 'lib/nhentai-api.rb', line 359 def languages? !@client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}).nil? end |
#page(page = 1) ⇒ String
Give the URL of a given page of a doujinshi
75 76 77 78 79 |
# File 'lib/nhentai-api.rb', line 75 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 ⇒ Array
Give the URL of a all pages of a doujinshi
89 90 91 |
# File 'lib/nhentai-api.rb', line 89 def pages (1..@count_pages).map { |page| page(page) } end |
#parodies ⇒ Object
Give all parodies of a doujinshi
194 195 196 197 198 199 |
# File 'lib/nhentai-api.rb', line 194 def parodies res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#parodies? ⇒ Boolean
Check if a particular doujinshi have some parodies
219 220 221 |
# File 'lib/nhentai-api.rb', line 219 def parodies? !@client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}).nil? end |
#tags ⇒ Array
Give all tags of a doujinshi
155 156 157 158 159 160 |
# File 'lib/nhentai-api.rb', line 155 def res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>}) return [] if res.nil? (res[1]) end |
#tags? ⇒ Bool
Check if a particular doujinshi have some tags
184 185 186 |
# File 'lib/nhentai-api.rb', line 184 def !@client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>}).nil? end |
#thumbnail(page = 1) ⇒ String
Give the thumbnail’s URL of a given page of a doujinshi
103 104 105 106 107 |
# File 'lib/nhentai-api.rb', line 103 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 ⇒ Array
Give the URL of a all thumbnails of a doujinshi
117 118 119 |
# File 'lib/nhentai-api.rb', line 117 def thumbnails (1..@count_pages).map { |page| thumbnail(page) } end |
#title ⇒ String
Give the title of a doujinshi
47 48 49 |
# File 'lib/nhentai-api.rb', line 47 def title @client.body.match(/"pretty">(.*?)</)[1] end |
#upload_date ⇒ Integer
Give the upload date of a doujinshi
143 144 145 |
# File 'lib/nhentai-api.rb', line 143 def upload_date Time.iso8601(@client.body.match(/<time .+ datetime="(.*?)"/)[1]) end |