Class: Mangadex::MangadexObject
Direct Known Subclasses
Api::Response, Api::Response::Error, Artist, Author, Chapter, CoverArt, CustomList, Manga, Rating, Relationship, Report, ReportReason, ScanlationGroup, Statistic, Statistic::Comments, Statistic::Rating, Tag, Thread, Upload, User
Instance Attribute Summary
Attributes included from Internal::WithAttributes
#attributes, #id, #related_type, #relationships, #type
Class Method Summary collapse
Instance Method Summary collapse
- #eq?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(**args) ⇒ MangadexObject
constructor
A new instance of MangadexObject.
- #inspect ⇒ Object
Methods included from Concern
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
Constructor Details
#initialize(**args) ⇒ MangadexObject
Returns a new instance of MangadexObject.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mangadex/mangadex_object.rb', line 18 def initialize(**args) args.keys.each do |attribute| original_attribute = attribute attribute = Mangadex::Utils.underscore(attribute.to_s) attribute_to_set = "#{attribute}=" if respond_to?(attribute_to_set) if %w(created_at updated_at publish_at).include?(attribute) args[original_attribute] = DateTime.parse(args[original_attribute]) end send(attribute_to_set, args[original_attribute]) else warn("Ignoring setter `#{attribute_to_set}` on #{self.class.name}...") end end self.type = self.class.type if self.type.blank? end |
Class Method Details
Instance Method Details
#eq?(other) ⇒ Boolean
38 39 40 41 42 |
# File 'lib/mangadex/mangadex_object.rb', line 38 def eq?(other) return id == other.id if respond_to?(:id) && other.respond_to?(:id) super end |
#hash ⇒ Object
44 45 46 |
# File 'lib/mangadex/mangadex_object.rb', line 44 def hash id.hash end |
#inspect ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mangadex/mangadex_object.rb', line 48 def inspect string = "#<#{self.class.name}:#{self.object_id} " fields = self.class.attributes_to_inspect.map do |field| value = self.send(field) if !value.nil? "@#{field}=\"#{value}\"" end rescue => error "@#{field}[!]={#{error.class.name}: #{error.}}" end.compact string << fields.join(" ") << ">" end |