Class: AddressLabel

Inherits:
Object
  • Object
show all
Defined in:
app/models/address_label.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, address_field, name_surrounding_field, personal_title = '', company = '') ⇒ AddressLabel

Returns a new instance of AddressLabel.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/address_label.rb', line 8

def initialize(name, address_field, name_surrounding_field, personal_title = '', company = '')
  self.name = name
  self.company = company
  self.postal_address = address_field.try(:value)
  self.postal_code = address_field.try(:postal_code)
  self.country_code = address_field.try(:country_code)
  self.country = address_field.try(:geo_location).try(:country)
  self.city = address_field.try(:geo_location).try(:city)
  self.text_above_name = name_surrounding_field.try(:text_above_name).try(:strip)
  self.text_below_name = name_surrounding_field.try(:text_below_name).try(:strip)
  self.name_prefix = name_surrounding_field.try(:name_prefix).try(:strip)
  self.name_suffix = name_surrounding_field.try(:name_suffix).try(:strip)
  self.personal_title = personal_title
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



4
5
6
# File 'app/models/address_label.rb', line 4

def city
  @city
end

#companyObject

Returns the value of attribute company.



3
4
5
# File 'app/models/address_label.rb', line 3

def company
  @company
end

#countryObject

Returns the value of attribute country.



4
5
6
# File 'app/models/address_label.rb', line 4

def country
  @country
end

#country_codeObject

Returns the value of attribute country_code.



4
5
6
# File 'app/models/address_label.rb', line 4

def country_code
  @country_code
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/address_label.rb', line 2

def name
  @name
end

#name_prefixObject

Returns the value of attribute name_prefix.



5
6
7
# File 'app/models/address_label.rb', line 5

def name_prefix
  @name_prefix
end

#name_suffixObject

Returns the value of attribute name_suffix.



5
6
7
# File 'app/models/address_label.rb', line 5

def name_suffix
  @name_suffix
end

#personal_titleObject

Returns the value of attribute personal_title.



6
7
8
# File 'app/models/address_label.rb', line 6

def personal_title
  @personal_title
end

#postal_addressObject

Returns the value of attribute postal_address.



4
5
6
# File 'app/models/address_label.rb', line 4

def postal_address
  @postal_address
end

#postal_codeObject

Returns the value of attribute postal_code.



4
5
6
# File 'app/models/address_label.rb', line 4

def postal_code
  @postal_code
end

#text_above_nameObject

Returns the value of attribute text_above_name.



5
6
7
# File 'app/models/address_label.rb', line 5

def text_above_name
  @text_above_name
end

#text_below_nameObject

Returns the value of attribute text_below_name.



5
6
7
# File 'app/models/address_label.rb', line 5

def text_below_name
  @text_below_name
end

Instance Method Details

#postal_address_with_name_surroundingObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/address_label.rb', line 27

def postal_address_with_name_surrounding
  # text_before_the_name = name_prefix || ""
  # text_before_the_name += " #{personal_title}" if name_prefix != personal_title
  # ("#{text_above_name}\n" + 
  #   "#{text_before_the_name} #{name} #{name_suffix}\n" + 
  #   "#{text_below_name}\n" +
  #   (postal_address || "")
  # )
  (
    "#{text_above_name}\n" +
    "#{name_prefix} #{name} #{name_suffix}\n" +
    "#{text_below_name}\n" +
    "#{company}\n" + 
    (postal_address || "")
  )
  .gsub('  ', ' ')
  .gsub("\n\n\n", "\n")
  .gsub("\n\n", "\n")
  .gsub(" \n", "\n")
  .gsub("\n ", "\n")
  .strip
end

#to_sObject



23
24
25
# File 'app/models/address_label.rb', line 23

def to_s
  postal_address_with_name_surrounding
end