diff options
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? |