Class: Mangadex::ContentRating
- Inherits:
-
Object
- Object
- Mangadex::ContentRating
- 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
- #<=>(other) ⇒ Object
-
#initialize(value) ⇒ ContentRating
constructor
A new instance of ContentRating.
- #score ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value) ⇒ ContentRating
Returns a new instance of ContentRating.
37 38 39 |
# File 'lib/mangadex/content_rating.rb', line 37 def initialize(value) @value = ensure_value!(value.to_s) end |
Class Method Details
.anything_below(content_rating) ⇒ Object
27 28 29 |
# File 'lib/mangadex/content_rating.rb', line 27 def self.anything_below() SCORES.keys.map { |key| ContentRating.new(key) }.select { |record| record <= }.sort end |
.parse(content_ratings) ⇒ Object
32 33 34 |
# File 'lib/mangadex/content_rating.rb', line 32 def self.parse() .map { || ContentRating.new() }.uniq end |
Instance Method Details
#<=>(other) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/mangadex/content_rating.rb', line 47 def <=>(other) other_score = if other.is_a?(ContentRating) other.score else ContentRating.new(other).score end score <=> other_score end |
#score ⇒ Object
61 62 63 |
# File 'lib/mangadex/content_rating.rb', line 61 def score SCORES[value] end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/mangadex/content_rating.rb', line 66 def to_s value.to_s end |
#value ⇒ Object
42 43 44 |
# File 'lib/mangadex/content_rating.rb', line 42 def value ActiveSupport::StringInquirer.new(@value) end |