Class: Mangadex::Chapter
Instance Attribute Summary
#attributes, #id, #related_type, #relationships, #type
Class Method Summary
collapse
Instance Method Summary
collapse
#eq?, #hash, #initialize, #inspect
Class Method Details
.attributes_to_inspect ⇒ Object
112
113
114
|
# File 'lib/mangadex/chapter.rb', line 112
def self.attributes_to_inspect
[:id, :type, :title, :volume, :chapter, :page_count, :publish_at]
end
|
.delete(id) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/mangadex/chapter.rb', line 63
def self.delete(id)
Mangadex::Internal::Definition.must(id)
Mangadex::Internal::Request.delete(
'/chapter/%{id}' % {id: id},
)
end
|
.get(id, **args) ⇒ Object
Also known as:
view
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/mangadex/chapter.rb', line 34
def self.get(id, **args)
Mangadex::Internal::Definition.must(id)
Mangadex::Internal::Request.get(
'/chapter/%{id}' % {id: id},
Mangadex::Internal::Definition.validate(args, {
includes: { accepts: [String] },
}),
)
end
|
.list(**args) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/mangadex/chapter.rb', line 25
def self.list(**args)
Mangadex::Internal::Request.get(
'/chapter',
Mangadex::Internal::Definition.chapter_list(args),
content_rating: true,
)
end
|
.update(id, **args) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/mangadex/chapter.rb', line 46
def self.update(id, **args)
Mangadex::Internal::Definition.must(id)
Mangadex::Internal::Request.put(
'/chapter/%{id}' % {id: id},
payload: Mangadex::Internal::Definition.validate(args, {
title: { accepts: String },
volume: { accepts: String },
chapter: { accepts: String },
translated_language: { accepts: %r{^[a-zA-Z\-]{2,5}$} },
groups: { accepts: [String] },
version: { accepts: Integer, required: true },
}),
)
end
|
Instance Method Details
#as_json ⇒ Object
105
106
107
108
109
110
|
# File 'lib/mangadex/chapter.rb', line 105
def as_json(*)
super.merge({
locale_name: locale_name,
preview_image_url: preview_image_url,
})
end
|
#locale ⇒ Object
81
82
83
84
85
86
|
# File 'lib/mangadex/chapter.rb', line 81
def locale
found_locale = translated_language.split('-').first
return if found_locale.nil?
ISO_639.find(found_locale)
end
|
#locale_name ⇒ Object
89
90
91
|
# File 'lib/mangadex/chapter.rb', line 89
def locale_name
locale&.english_name
end
|
#page_count ⇒ Object
94
95
96
|
# File 'lib/mangadex/chapter.rb', line 94
def page_count
Array(data).count
end
|
#preview_image_url ⇒ Object
99
100
101
102
103
|
# File 'lib/mangadex/chapter.rb', line 99
def preview_image_url
return if data_saver.empty?
"https://uploads.mangadex.org/data-saver/#{attributes.hash}/#{data_saver.first}"
end
|
#title ⇒ Object
76
77
78
|
# File 'lib/mangadex/chapter.rb', line 76
def title
attributes&.title.presence || chapter.presence && "Chapter #{chapter}" || "N/A"
end
|