Class: Medivo::PrimaryInsurance

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::Xml, ActiveModel::Validations
Defined in:
app/models/medivo/primary_insurance.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ PrimaryInsurance

Returns a new instance of PrimaryInsurance.



9
10
11
# File 'app/models/medivo/primary_insurance.rb', line 9

def initialize(attributes = {})
  @attributes = attributes
end

Instance Method Details

#attributesObject



17
18
19
# File 'app/models/medivo/primary_insurance.rb', line 17

def attributes
  @attributes.stringify_keys
end

#read_attribute_for_validation(key) ⇒ Object



13
14
15
# File 'app/models/medivo/primary_insurance.rb', line 13

def read_attribute_for_validation(key)
  @attributes[key]
end

#validate(record) ⇒ Object

for use by InsuranceOrder to validate its primary insurance



22
23
24
25
26
27
28
29
30
# File 'app/models/medivo/primary_insurance.rb', line 22

def validate(record)
  primary_insurance = record.attributes['primary_insurance']
  record.errors.add(:primary_insurance, "primary_insurance field must be present") and return unless primary_insurance
  record.errors.add(:primary_insurance, "primary_insurance field must be of PrimaryInsurance class") and return unless primary_insurance.is_a? PrimaryInsurance
  primary_insurance.valid?
  primary_insurance.errors.messages.each do |field, value|
    record.errors.add(:"primary_insurance.#{field}", value.first)
  end
end