From 5b742c1b095da2287358af0209e246fdf7452ac7 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 6 Oct 2015 21:10:13 +0200 Subject: Allow creation of bands with no params. --- lib/band.rb | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'lib/band.rb') diff --git a/lib/band.rb b/lib/band.rb index ac0a9db..61efcee 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -6,27 +6,30 @@ class Band attr_reader :name, :city, :website, :label, :short_bio, :contact, :members, :songs attr_reader :errors - def initialize(params) + def initialize(params = nil) @errors = [] - @name = params['name'] - @city = params['city'] - @website = params['website'] - @label = params['label'] - @short_bio = params['shortbio'] - - @contact = Contact.new(params['contact']) - - @members = [] - if params['members'] - params['members'].each do |k, m| - @members << Member.new(m) + + if params + @name = params['name'] + @city = params['city'] + @website = params['website'] + @label = params['label'] + @short_bio = params['shortbio'] + + @contact = Contact.new(params['contact']) + + @members = [] + if params['members'] + params['members'].each do |k, m| + @members << Member.new(m) + end end - end - @songs = [] - if params['songs'] - params['songs'].each do |k, s| - @songs << Song.new(s) + @songs = [] + if params['songs'] + params['songs'].each do |k, s| + @songs << Song.new(s) + end end end end -- cgit v1.2.3