Class: BootstrapValidatorRails::Validators::Numericality
- Inherits:
-
Validator
- Object
- Validator
- BootstrapValidatorRails::Validators::Numericality
show all
- Defined in:
- lib/bootstrap_validator_rails/validators/numericality_validator.rb
Instance Method Summary
collapse
Methods inherited from Validator
#initialize, #unsupported?, #validator_options
Instance Method Details
#generate_data ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/bootstrap_validator_rails/validators/numericality_validator.rb', line 4
def generate_data
data = {}
return data if unsupported?
options = validator_options
data[:bv_numeric] = 'true'
data[:bv_numeric_separator] = '.'
data.merge(generate_options)
end
|
#generate_message ⇒ Object
16
17
18
|
# File 'lib/bootstrap_validator_rails/validators/numericality_validator.rb', line 16
def generate_message
@record.errors.generate_message(@method, :presence, {default: 'should be a number'})
end
|
#generate_options ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/bootstrap_validator_rails/validators/numericality_validator.rb', line 20
def generate_options
options = @validator.options
data = {}
if options[:only_integer].present?
data[:bv_integer] = 'true'
end
if options[:greater_than].present?
data[:bv_greaterthan] = 'true'
data[:bv_greaterthan_inclusive] = 'false'
data[:bv_greaterthan_value] = options[:greater_than]
end
if options[:greater_than_or_equal_to].present?
data[:bv_greaterthan] = 'true'
data[:bv_greaterthan_inclusive] = 'true'
data[:bv_greaterthan_value] = options[:greater_than_or_equal_to]
end
if options[:less_than].present?
data[:bv_lessthan] = 'true'
data[:bv_lessthan_inclusive] = 'false'
data[:bv_lessthan_value] = options[:less_than]
end
if options[:less_than_or_equal_to].present?
data[:bv_lessthan] = 'true'
data[:bv_lessthan_inclusive] = 'true'
data[:bv_lessthan_value] = options[:less_than_or_equal_to]
end
if options[:odd].present?
data[:bv_step] = 'true'
data[:bv_step_message] = 'should be odd'
data[:bv_step_base] = '1'
data[:bv_step_step] = '2'
end
if options[:even].present?
data[:bv_step] = 'true'
data[:bv_step_message] = 'should be even'
data[:bv_step_base] = '0'
data[:bv_step_step] = '2'
end
data
end
|