Class: Mangadex::Statistic

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

Defined Under Namespace

Classes: Comments, Rating

Instance Attribute Summary collapse

Attributes included from Internal::WithAttributes

#attributes, #id, #related_type, #relationships, #type

Class 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

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



26
27
28
# File 'lib/mangadex/statistic.rb', line 26

def comments
  @comments
end

#followsObject

Returns the value of attribute follows.



26
27
28
# File 'lib/mangadex/statistic.rb', line 26

def follows
  @follows
end

#ratingObject

Returns the value of attribute rating.



26
27
28
# File 'lib/mangadex/statistic.rb', line 26

def rating
  @rating
end

Class Method Details

.attributes_to_inspectObject



74
75
76
# File 'lib/mangadex/statistic.rb', line 74

def self.attributes_to_inspect
  [:follows, :rating, :comments]
end

.from_data(data) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mangadex/statistic.rb', line 32

def from_data(data)
  results = if data.is_a?(Array)
    data.map do |item|
      from_data(item)
    end
  else
    data.keys.map do |manga_id|
      statistics = data[manga_id]
      new(
        rating: Mangadex::Statistic::Rating.from_data(statistics['rating'], direct: true),
        comments: Mangadex::Statistic::Comments.from_data(statistics['comments'], direct: true),
        follows: statistics['follows'],
      )
    end
  end

  return results.first if results.length == 1
  Mangadex::Api::Response::Collection.new(results)
end

.get(uuid, raw: false) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/mangadex/statistic.rb', line 54

def self.get(uuid, raw: false)
  Mangadex::Internal::Definition.must(uuid)

  Mangadex::Internal::Request.get(
    '/statistics/manga/%{uuid}' % {uuid: uuid},
    raw: raw,
  )
end

.list(raw: false, **args) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/mangadex/statistic.rb', line 64

def self.list(raw: false, **args)
  Mangadex::Internal::Request.get(
    '/statistics/manga',
    Mangadex::Internal::Definition.validate(args, {
      manga: { accepts: [String], converts: :to_a },
    }),
    raw: raw,
  )
end