Class: Mangadex::Api::Response
- Inherits:
-
MangadexObject
- Object
- MangadexObject
- Mangadex::Api::Response
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/mangadex/api/response.rb
Defined Under Namespace
Classes: Collection, Error
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#raw_data ⇒ Object
Returns the value of attribute raw_data.
-
#response ⇒ Object
Returns the value of attribute response.
-
#result ⇒ Object
Returns the value of attribute result.
-
#total ⇒ Object
Returns the value of attribute total.
Attributes included from Internal::WithAttributes
#attributes, #id, #related_type, #relationships, #type
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #count ⇒ Object (also: #size, #length)
- #each(&block) ⇒ Object
- #errored?(status = nil) ⇒ Boolean
- #first ⇒ Object
- #last ⇒ Object
- #more_results? ⇒ Boolean
- #to_a ⇒ Object
Methods inherited from MangadexObject
#eq?, #hash, #initialize, #inspect
Methods included from Concern
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
Constructor Details
This class inherits a constructor from Mangadex::MangadexObject
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/mangadex/api/response.rb', line 8 def data @data end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/mangadex/api/response.rb', line 8 def errors @errors end |
#limit ⇒ Object
Returns the value of attribute limit.
9 10 11 |
# File 'lib/mangadex/api/response.rb', line 9 def limit @limit end |
#offset ⇒ Object
Returns the value of attribute offset.
9 10 11 |
# File 'lib/mangadex/api/response.rb', line 9 def offset @offset end |
#raw_data ⇒ Object
Returns the value of attribute raw_data.
10 11 12 |
# File 'lib/mangadex/api/response.rb', line 10 def raw_data @raw_data end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/mangadex/api/response.rb', line 8 def response @response end |
#result ⇒ Object
Returns the value of attribute result.
8 9 10 |
# File 'lib/mangadex/api/response.rb', line 8 def result @result end |
#total ⇒ Object
Returns the value of attribute total.
9 10 11 |
# File 'lib/mangadex/api/response.rb', line 9 def total @total end |
Class Method Details
.attributes_to_inspect ⇒ Object
12 13 14 |
# File 'lib/mangadex/api/response.rb', line 12 def self.attributes_to_inspect %i(result errors limit offset total data) end |
.coerce(data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mangadex/api/response.rb', line 32 def self.coerce(data) if data['errors'] coerce_errors(data) elsif data['response'] == 'entity' coerce_entity(data) elsif data['response'] == 'collection' coerce_collection(data) elsif data.keys.include?('statistics') coerce_statistics(data) else data end end |
Instance Method Details
#as_json ⇒ Object
85 86 87 |
# File 'lib/mangadex/api/response.rb', line 85 def as_json(*) Hash(raw_data) end |
#count ⇒ Object Also known as: size, length
59 60 61 |
# File 'lib/mangadex/api/response.rb', line 59 def count data.is_a?(Array) ? data.count : nil end |
#each(&block) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/mangadex/api/response.rb', line 65 def each(&block) if data.is_a?(Array) data.each(&block) else raise ArgumentError, "Expect data to be Array, but got #{data.class}" end end |
#errored?(status = nil) ⇒ Boolean
46 47 48 49 50 51 |
# File 'lib/mangadex/api/response.rb', line 46 def errored?(status=nil) errored = Array(errors).any? return errored if status.nil? errors.select { |error| error.status.to_s == status.to_s }.any? end |
#first ⇒ Object
77 78 79 |
# File 'lib/mangadex/api/response.rb', line 77 def first to_a.first end |
#last ⇒ Object
81 82 83 |
# File 'lib/mangadex/api/response.rb', line 81 def last to_a.last end |
#more_results? ⇒ Boolean
53 54 55 56 57 |
# File 'lib/mangadex/api/response.rb', line 53 def more_results? return unless data.is_a?(Array) total > data.count end |
#to_a ⇒ Object
73 74 75 |
# File 'lib/mangadex/api/response.rb', line 73 def to_a each.to_a end |