Class: Trafaret::Symbol
- Defined in:
- lib/trafaret/validators.rb
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
Methods inherited from Validator
#&, #===, #add, #call, #convert, #failure, #initialize, #perform_convert, #to, #|
Constructor Details
This class inherits a constructor from Trafaret::Validator
Instance Method Details
#prepare ⇒ Object
94 95 96 97 |
# File 'lib/trafaret/validators.rb', line 94 def prepare @sym = @args.first.to_sym @str = @args.first.to_s.freeze end |
#validate(data) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/trafaret/validators.rb', line 99 def validate(data) case data when ::String @str == data ? @sym : failure('Not equal') when ::Symbol @sym == data ? @sym : failure('Not equal') else failure('Not a String or a Symbol') end end |