Class: Renalware::Address

Inherits:
ApplicationRecord show all
Defined in:
app/values/renalware/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_validationObject

Set to true to avoid address validation - useful when archiving a letter with a migrated address that might not have a postcode for instance



13
14
15
# File 'app/values/renalware/address.rb', line 13

def skip_validation
  @skip_validation
end

Class Method Details

.reject_if_blankObject



17
18
19
20
21
22
# File 'app/values/renalware/address.rb', line 17

def self.reject_if_blank
  lambda { |attrs|
    %w(name organisation_name street_1 street_2 street_3 town county postcode)
      .all? { |a| attrs[a].blank? }
  }
end

Instance Method Details

#copy_from(source) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/values/renalware/address.rb', line 24

def copy_from(source)
  return self if source.blank?

  self.name = source.name
  self.organisation_name = source.organisation_name
  self.street_1 = source.street_1
  self.street_2 = source.street_2
  self.street_3 = source.street_3
  self.town = source.town
  self.county = source.county
  self.postcode = source.postcode
  self.country = source.country
  self
end

#streetObject



45
46
47
# File 'app/values/renalware/address.rb', line 45

def street
  [street_1, street_2, street_3].reject(&:blank?).join(", ")
end

#to_s(format = nil) ⇒ Object



39
40
41
42
43
# File 'app/values/renalware/address.rb', line 39

def to_s(format = nil)
  parts = [name, organisation_name, street_1, street_2, street_3, town, county]
  parts += [postcode, country] unless format == :without_postcode
  parts.reject(&:blank?).join(", ")
end