class Mangadex::ContentRating

Constants

SCORES
VALUES

Public Class Methods

anything_below(content_rating) click to toggle source
# 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
new(value) click to toggle source
# File lib/mangadex/content_rating.rb, line 32
def initialize(value)
  @value = ensure_value!(value.to_s)
end
parse(content_ratings) click to toggle source
# File lib/mangadex/content_rating.rb, line 27
def self.parse(content_ratings)
  content_ratings.map { |content_rating| ContentRating.new(content_rating) }.uniq
end

Public Instance Methods

<=>(other) click to toggle source
# 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
method_missing(method_name, *args, **kwargs) click to toggle source
# File lib/mangadex/content_rating.rb, line 65
def method_missing(method_name, *args, **kwargs)
  value.send(method_name, *args, **kwargs)
end
score() click to toggle source
# File lib/mangadex/content_rating.rb, line 56
def score
  SCORES[value]
end
to_s() click to toggle source
# File lib/mangadex/content_rating.rb, line 61
def to_s
  value.to_s
end
value() click to toggle source
# File lib/mangadex/content_rating.rb, line 37
def value
  StringInquirer.new(@value)
end

Private Instance Methods

ensure_value!(value) click to toggle source
# File lib/mangadex/content_rating.rb, line 72
def ensure_value!(value)
  return value if value.is_a?(ContentRating)
  return value if VALUES.include?(value)

  raise ArgumentError, "Invalid content rating: '#{value}'. Must be one of #{VALUES}"
end