Class: Mangadex::Chapter
Instance Attribute Summary
#attributes, #id, #relationships, #type
Class Method Summary
collapse
Instance Method Summary
collapse
#eq?, #hash, #initialize, #inspect
Class Method Details
.attributes_to_inspect ⇒ Object
101
102
103
|
# File 'lib/mangadex/chapter.rb', line 101
def self.attributes_to_inspect
[:id, :type, :title, :volume, :chapter, :page_count, :publish_at]
end
|
.delete(id) ⇒ Object
58
59
60
61
62
|
# File 'lib/mangadex/chapter.rb', line 58
def self.delete(id)
Mangadex::Internal::Request.delete(
'/chapter/%{id}' % {id: id},
)
end
|
.get(id, **args) ⇒ Object
.update(id, **args) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/mangadex/chapter.rb', line 43
def self.update(id, **args)
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
94
95
96
97
98
99
|
# File 'lib/mangadex/chapter.rb', line 94
def as_json(*)
super.merge({
locale_name: locale_name,
preview_image_url: preview_image_url,
})
end
|
#locale ⇒ Object
70
71
72
73
74
75
|
# File 'lib/mangadex/chapter.rb', line 70
def locale
found_locale = translated_language.split('-').first
return if found_locale.nil?
ISO_639.find(found_locale)
end
|
#locale_name ⇒ Object
78
79
80
|
# File 'lib/mangadex/chapter.rb', line 78
def locale_name
locale&.english_name
end
|
#page_count ⇒ Object
83
84
85
|
# File 'lib/mangadex/chapter.rb', line 83
def page_count
Array(data).count
end
|
#preview_image_url ⇒ Object
88
89
90
91
92
|
# File 'lib/mangadex/chapter.rb', line 88
def preview_image_url
return if data_saver.empty?
"https://uploads.mangadex.org/data-saver/#{attributes.hash}/#{data_saver.first}"
end
|
#title ⇒ Object
65
66
67
|
# File 'lib/mangadex/chapter.rb', line 65
def title
attributes&.title.presence || chapter.presence && "Chapter #{chapter}" || "N/A"
end
|