Class: Mangadex::Internal::Definitions::Accepts
- Defined in:
- lib/mangadex/internal/definitions/accepts.rb
Defined Under Namespace
Classes: Possibility
Constant Summary collapse
- VALID_CONDITIONS =
[:and, :or]
Instance Method Summary collapse
-
#initialize(array: nil, class: nil, value: nil, condition: :and) ⇒ Accepts
constructor
A new instance of Accepts.
- #validate!(value) ⇒ Object
Constructor Details
#initialize(array: nil, class: nil, value: nil, condition: :and) ⇒ Accepts
Returns a new instance of Accepts.
19 20 21 22 23 24 |
# File 'lib/mangadex/internal/definitions/accepts.rb', line 19 def initialize(array: nil, class: nil, value: nil, condition: :and) @array = array @class = binding.local_variable_get(:class) @value = value @condition = ensure_valid_condition!(condition.to_s.to_sym) end |
Instance Method Details
#validate!(value) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/mangadex/internal/definitions/accepts.rb', line 26 def validate!(value) valid = if @condition == :or validate_or!(value) else validate_and!(value) end raise ArgumentError, "Value `#{value}` must be #{nature}: #{possibilities}" unless valid end |