Class: Mangadex::Relationship
- Inherits:
-
MangadexObject
- Object
- MangadexObject
- Mangadex::Relationship
- Defined in:
- lib/mangadex/relationship.rb
Constant Summary collapse
- RELATED_VALUES =
%w( monochrome main_story adapted_from based_on prequel side_story doujinshi same_franchise shared_universe sequel spin_off alternate_story preserialization colored serialization ).freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
-
#related ⇒ Object
Returns the value of attribute related.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from Internal::WithAttributes
Class Method Summary collapse
- .attributes_to_inspect ⇒ Object
-
.from_data(data, source_obj = nil) ⇒ Object
data: Relationship data source_obj: The object to witch the object belongs to.
Instance Method Summary collapse
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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(value) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/mangadex/relationship.rb', line 64 def method_missing(value) return super unless value.end_with?("?") = value.to_s.split("?").first return super unless RELATED_VALUES.include?() !.nil? && == end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/mangadex/relationship.rb', line 4 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/mangadex/relationship.rb', line 4 def id @id end |
#related ⇒ Object
Returns the value of attribute related.
4 5 6 |
# File 'lib/mangadex/relationship.rb', line 4 def @related end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/mangadex/relationship.rb', line 4 def type @type end |
Class Method Details
.attributes_to_inspect ⇒ Object
59 60 61 |
# File 'lib/mangadex/relationship.rb', line 59 def self.attributes_to_inspect [:id, :type, :related] end |
.from_data(data, source_obj = nil) ⇒ Object
data: Relationship data source_obj: The object to witch the object belongs to
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mangadex/relationship.rb', line 27 def from_data(data, source_obj = nil) data = data.transform_keys(&:to_s) klass = class_for_relationship_type(data['type']) if klass && data['attributes']&.any? return klass.from_data(data, related_type: data['related'], source_obj: source_obj) end relationships = [source_obj] if source_obj new( id: data['id'], type: data['type'], attributes: OpenStruct.new(data['attributes']), related: data['related'], relationships: relationships, ) end |