Sha256: 7798961929cdbb2fc810eb868794651545365bd0d90c4badcfa388f566df1ded
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
# typed: false require "active_support/string_inquirer" require "active_support/core_ext/module/delegation" module Mangadex class ContentRating extend T::Sig include Comparable VALUES = [ SAFE = 'safe', SUGGESTIVE = 'suggestive', EROTICA = 'erotica', PORNOGRAPHIC = 'pornographic', ].freeze SCORES = { SAFE => 0, SUGGESTIVE => 1, EROTICA => 2, PORNOGRAPHIC => 3, }.freeze delegate_missing_to :value sig { params(content_rating: T::Api::ContentRating).returns(T::Array[ContentRating]) } def self.anything_below(content_rating) SCORES.keys.map { |key| ContentRating.new(key) }.select { |record| record <= content_rating }.sort end sig { params(value: T.any(T::Api::Text, T::Api::ContentRating)).void } def initialize(value) @value = ensure_value!(value.to_s) end sig { returns(ActiveSupport::StringInquirer) } def value ActiveSupport::StringInquirer.new(@value) end sig { params(other: T.any(ContentRating, String, Symbol)).returns(Integer) } def <=>(other) other_score = if other.is_a?(ContentRating) other.score else ContentRating.new(other).score end score <=> other_score end alias_method :safer_than?, :< alias_method :spicier_than?, :> sig { returns(Integer) } def score SCORES[value] end sig { returns(String) } def to_s value.to_s end private sig { params(value: T.any(T::Api::Text, T::Api::ContentRating)).returns(T.any(T::Api::Text, T::Api::ContentRating)) } 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mangadex-5.3.3 | lib/mangadex/content_rating.rb |