Class: Mangadex::Internal::Definitions::Base
- Defined in:
- lib/mangadex/internal/definitions/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#accepts ⇒ Object
readonly
Returns the value of attribute accepts.
-
#converts ⇒ Object
readonly
Returns the value of attribute converts.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #error_message ⇒ Object
-
#initialize(value, key:, accepts:, required: false, converts: nil) ⇒ Base
constructor
A new instance of Base.
- #valid? ⇒ Boolean
- #validate ⇒ Object
- #validate! ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value, key:, accepts:, required: false, converts: nil) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 |
# File 'lib/mangadex/internal/definitions/base.rb', line 9 def initialize(value, key:, accepts:, required: false, converts: nil) @value = value @key = key @accepts = accepts @required = required @converts = converts @errors = Array.new end |
Instance Attribute Details
#accepts ⇒ Object (readonly)
Returns the value of attribute accepts.
7 8 9 |
# File 'lib/mangadex/internal/definitions/base.rb', line 7 def accepts @accepts end |
#converts ⇒ Object (readonly)
Returns the value of attribute converts.
7 8 9 |
# File 'lib/mangadex/internal/definitions/base.rb', line 7 def converts @converts end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/mangadex/internal/definitions/base.rb', line 7 def errors @errors end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/mangadex/internal/definitions/base.rb', line 7 def key @key end |
Instance Method Details
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/mangadex/internal/definitions/base.rb', line 46 def empty? converted_value.respond_to?(:empty?) ? converted_value.empty? : converted_value.to_s.strip.empty? end |
#error_message ⇒ Object
40 41 42 43 44 |
# File 'lib/mangadex/internal/definitions/base.rb', line 40 def return unless errors.any? end |
#valid? ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/mangadex/internal/definitions/base.rb', line 33 def valid? validate! true rescue ArgumentError false end |
#validate ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/mangadex/internal/definitions/base.rb', line 18 def validate validate_required return if !@required && empty? validate_accepts nil end |
#validate! ⇒ Object
27 28 29 30 31 |
# File 'lib/mangadex/internal/definitions/base.rb', line 27 def validate! validate raise_if_any_errors! end |
#value ⇒ Object
50 51 52 |
# File 'lib/mangadex/internal/definitions/base.rb', line 50 def value converted_value end |