Class: Fulcrum::RecordValidator

Inherits:
BaseValidator show all
Defined in:
lib/fulcrum/validators/record_validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#data, #errors

Instance Method Summary collapse

Methods inherited from BaseValidator

#add_error, #initialize, #valid?

Constructor Details

This class inherits a constructor from Fulcrum::BaseValidator

Instance Method Details

#validate!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fulcrum/validators/record_validator.rb', line 3

def validate!
  if data['record'].kind_of?(Hash) && !data['record'].empty?
    add_error('record', 'form_id', 'cannot be blank') if data['record']['form_id'].blank?
    if data['record']['latitude'].to_f == 0.0 || data['record']['longitude'] == 0.0
      add_error('record', 'coordinates', 'must be in WGS84 format')
    end
    if !data['record']['form_values'].kind_of?(Hash) || data['record']['form_values'].blank?
      add_error('record', 'form_values', 'must be a non-empty hash')
    end
  else
    @errors['record'] = ['must be a non-empty hash']
  end
  return valid?
end