Class: OneSignal::Notification::EnumAttributeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/onesignal/models/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datatype, allowable_values) ⇒ EnumAttributeValidator

Returns a new instance of EnumAttributeValidator.



333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/onesignal/models/notification.rb', line 333

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.



331
332
333
# File 'lib/onesignal/models/notification.rb', line 331

def allowable_values
  @allowable_values
end

#datatypeObject (readonly)

Returns the value of attribute datatype.



330
331
332
# File 'lib/onesignal/models/notification.rb', line 330

def datatype
  @datatype
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


346
347
348
# File 'lib/onesignal/models/notification.rb', line 346

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