summaryrefslogtreecommitdiffstats
path: root/lib/contact.rb
blob: 5e6c475c5de26f2961313950196c9482cb5a05e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Contact
  attr_reader :name, :addr, :phone, :email

  def initialize(params = nil)
    if params
      @name = params['name']
      @addr = params['addr']
      @phone = params['phone']
      @email = params['email']
    end
  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"
    end

    if @phone.nil? || @phone.strip.empty?
      errors << "Du må oppgi et telefonnummer"
    end

    if @email.nil? || @email.strip.empty?
      errors << "Du må oppgi en epostadresse"
    end

    errors
  end
end