diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2017-09-09 16:54:50 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2017-09-09 16:56:06 +0200 |
commit | 032d46f65ac3bbfe5c05f96e6b68d0dfe2a4aa3d (patch) | |
tree | 3c9d5c6ee730730c8e281def9582974c1ec134de /lib | |
parent | a147a9a6c761d5d867c24bbea09f4d558591e07c (diff) | |
download | norsk-urskog-registrations-032d46f65ac3bbfe5c05f96e6b68d0dfe2a4aa3d.tar.gz norsk-urskog-registrations-032d46f65ac3bbfe5c05f96e6b68d0dfe2a4aa3d.tar.bz2 norsk-urskog-registrations-032d46f65ac3bbfe5c05f96e6b68d0dfe2a4aa3d.zip |
Split contact address into street, postcode and city.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/contact.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/contact.rb b/lib/contact.rb index 5e6c475..ffa33bf 100644 --- a/lib/contact.rb +++ b/lib/contact.rb @@ -1,23 +1,33 @@ class Contact - attr_reader :name, :addr, :phone, :email + attr_reader :name, :street, :postcode, :city, :phone, :email def initialize(params = nil) if params @name = params['name'] - @addr = params['addr'] + @street = params['street'] + @postcode = params['postcode'] + @city = params['city'] @phone = params['phone'] @email = params['email'] end end + def addr + "#{@street}, #{@postcode} #{@city}" + end + def validate! errors = [] if @name.nil? || @name.strip.empty? errors << "Du må oppgi en kontaktperson" end - if @addr.nil? || @addr.strip.empty? - errors << "Du må oppgi en kontaktadresse" + if @postcode.nil? || @postcode.strip.empty? + errors << "Du må oppgi et gyldig postnr." + end + + if @city.nil? || @city.strip.empty? + errors << "Du må oppgi poststed." end if @phone.nil? || @phone.strip.empty? |