Class: Mangadex::Relationship

Inherits:
MangadexObject show all
Defined in:
lib/mangadex/relationship.rb

Constant Summary collapse

%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 included from Internal::WithAttributes

#related_type, #relationships

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MangadexObject

#eq?, #hash, #initialize, #inspect

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



59
60
61
62
63
64
65
66
# File 'lib/mangadex/relationship.rb', line 59

def method_missing(value)
  return super unless value.end_with?("?")

  looking_for_related = value.to_s.split("?").first
  return super unless RELATED_VALUES.include?(looking_for_related)

  !related.nil? && related == looking_for_related
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/mangadex/relationship.rb', line 4

def attributes
  @attributes
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/mangadex/relationship.rb', line 4

def id
  @id
end

Returns the value of attribute related.



4
5
6
# File 'lib/mangadex/relationship.rb', line 4

def related
  @related
end

#typeObject

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_inspectObject



54
55
56
# File 'lib/mangadex/relationship.rb', line 54

def self.attributes_to_inspect
  [:id, :type, :related]
end

.from_data(data) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mangadex/relationship.rb', line 25

def from_data(data)
  data = data.with_indifferent_access
  klass = class_for_relationship_type(data['type'])

  if klass && data['attributes']&.any?
    return klass.from_data(data, related_type: data['related'])
  end

  new(
    id: data['id'],
    type: data['type'],
    attributes: OpenStruct.new(data['attributes']),
    related: data['related'],
  )
end