Class: DocSpring::Submission::EnumAttributeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/docspring/models/submission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datatype, allowable_values) ⇒ EnumAttributeValidator

Returns a new instance of EnumAttributeValidator.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/docspring/models/submission.rb', line 59

def initialize(datatype, allowable_values)
  @allowable_values = allowable_values.map do |value|
    case datatype.to_s
    when /Integer/i
      value.to_i
    when /Float/i
      value.to_f
    else
      value
    end
  end
end

Instance Attribute Details

#allowable_valuesObject (readonly)

Returns the value of attribute allowable_values.



57
58
59
# File 'lib/docspring/models/submission.rb', line 57

def allowable_values
  @allowable_values
end

#datatypeObject (readonly)

Returns the value of attribute datatype.



56
57
58
# File 'lib/docspring/models/submission.rb', line 56

def datatype
  @datatype
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/docspring/models/submission.rb', line 72

def valid?(value)
  !value || allowable_values.include?(value)
end