From 57af2ee2e51b614ac6e2fa81b1075a55d3c0c252 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 15 Oct 2015 10:11:56 +0200 Subject: Retain member and song info on errors in form. --- lib/member.rb | 14 ++++++++++---- lib/song.rb | 14 +++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/member.rb b/lib/member.rb index 0fb69b5..598b5f4 100644 --- a/lib/member.rb +++ b/lib/member.rb @@ -1,10 +1,16 @@ class Member attr_reader :name, :instrument, :age - def initialize(params) - @name = params['name'] - @instrument = params['instrument'] - @age = params['age'].to_i + def initialize(params = nil) + if params + @name = params['name'] + @instrument = params['instrument'] + @age = params['age'].to_i + else + @name = '' + @instrument = '' + @age = 0 + end end def to_s diff --git a/lib/song.rb b/lib/song.rb index 93172f2..482834e 100644 --- a/lib/song.rb +++ b/lib/song.rb @@ -1,13 +1,13 @@ class Song attr_reader :title, :time, :isrc, :composers, :performers, :notes - def initialize(params) - @title = params['title'] - @time = params['time'] - @isrc = params['isrc'] - @composers = params['composers'].split("\n") - @performers = params['performers'].split("\n") - @notes = params['notes'] + def initialize(params = nil) + @title = params ? params['title'] : '' + @time = params ? params['time'] : '' + @isrc = params ? params['isrc'] : '' + @composers = params ? params['composers'].split("\n") : [] + @performers = params ? params['performers'].split("\n") : [] + @notes = params ? params['notes'] : '' end def to_s -- cgit v1.2.3