Class: Mangadex::ContentRating
- Inherits:
-
Object
- Object
- Mangadex::ContentRating
show all
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- lib/mangadex/content_rating.rb
Constant Summary
collapse
- VALUES =
[
SAFE = 'safe',
SUGGESTIVE = 'suggestive',
EROTICA = 'erotica',
PORNOGRAPHIC = 'pornographic',
].freeze
- SCORES =
{
SAFE => 0,
SUGGESTIVE => 1,
EROTICA => 2,
PORNOGRAPHIC => 3,
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
32
33
34
|
# File 'lib/mangadex/content_rating.rb', line 32
def initialize(value)
@value = ensure_value!(value.to_s)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **kwargs) ⇒ Object
65
66
67
|
# File 'lib/mangadex/content_rating.rb', line 65
def method_missing(method_name, *args, **kwargs)
value.send(method_name, *args, **kwargs)
end
|
Class Method Details
.anything_below(content_rating) ⇒ Object
22
23
24
|
# File 'lib/mangadex/content_rating.rb', line 22
def self.anything_below(content_rating)
SCORES.keys.map { |key| ContentRating.new(key) }.select { |record| record <= content_rating }.sort
end
|
.parse(content_ratings) ⇒ Object
27
28
29
|
# File 'lib/mangadex/content_rating.rb', line 27
def self.parse(content_ratings)
content_ratings.map { |content_rating| ContentRating.new(content_rating) }.uniq
end
|
Instance Method Details
#<=>(other) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/mangadex/content_rating.rb', line 42
def <=>(other)
other_score = if other.is_a?(ContentRating)
other.score
else
ContentRating.new(other).score
end
score <=> other_score
end
|
56
57
58
|
# File 'lib/mangadex/content_rating.rb', line 56
def score
SCORES[value]
end
|
61
62
63
|
# File 'lib/mangadex/content_rating.rb', line 61
def to_s
value.to_s
end
|
37
38
39
|
# File 'lib/mangadex/content_rating.rb', line 37
def value
StringInquirer.new(@value)
end
|