Class: Location

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/location.rb

Instance Method Summary collapse

Instance Method Details

#displayObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/location.rb', line 25

def display
  return "Web" if self.is_web?
  d = []
  d << self.address1 unless self.address1.is_blank?
  d << self.address2 unless self.address2.is_blank?
  d << self.address3 unless self.address3.is_blank?
  d << self.city unless self.city.is_blank?
  d << self.postcode unless self.postcode.is_blank?
  d << self.country unless self.country.is_blank?

  d.join(", ")
end

#find_subregion(pc) ⇒ Object



42
43
44
# File 'app/models/location.rb', line 42

def find_subregion(pc)
  pc.strip.downcase=='web' ? Subregion.where(:name=>'Web').first : Subregion.find_by_postcode(pc)
end

#is_web?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/location.rb', line 21

def is_web?
  self.postcode.strip.downcase=='web'
end

#postcode_has_regionObject



14
15
16
17
18
19
# File 'app/models/location.rb', line 14

def postcode_has_region
  sr = find_subregion(postcode)
  if sr==nil
    errors.add(:postcode, "not recognised")
  end
end

#update_subregionObject



38
39
40
# File 'app/models/location.rb', line 38

def update_subregion
  self.subregion = find_subregion(self.postcode)
end