Class: Kafo::DataTypes::Enum
- Inherits:
-
Kafo::DataType
- Object
- Kafo::DataType
- Kafo::DataTypes::Enum
- Defined in:
- lib/kafo/data_types/enum.rb
Instance Method Summary collapse
-
#initialize(*permitted) ⇒ Enum
constructor
A new instance of Enum.
- #to_s ⇒ Object
- #valid?(input, errors = []) ⇒ Boolean
Methods inherited from Kafo::DataType
#condition_value, #dump_default, #multivalued?, new_from_string, parse_hash, register_type, split_arguments, #typecast, types, unregister_type
Constructor Details
#initialize(*permitted) ⇒ Enum
Returns a new instance of Enum.
4 5 6 |
# File 'lib/kafo/data_types/enum.rb', line 4 def initialize(*permitted) @permitted = permitted end |
Instance Method Details
#to_s ⇒ Object
8 9 10 |
# File 'lib/kafo/data_types/enum.rb', line 8 def to_s @permitted.map(&:inspect).join(' or ') end |
#valid?(input, errors = []) ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/kafo/data_types/enum.rb', line 12 def valid?(input, errors = []) unless input.is_a?(::String) errors << "#{input.inspect} is not a valid string" return false end errors << "#{input} must be one of #{@permitted.join(', ')}" unless @permitted.include?(input) return errors.empty? end |