Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Birthday Solution #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/birthday_list.rb
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
class Birthday

def initialize
@birthday_list = []
end

def add(name, birthday)
@birthday_list << { :name => name, :birthday => birthday }
@birthday_list
end

def print_list
@birthday_list.each do |person|
puts "#{person[:name]}, #{person[:birthday]}"
end
end

def today
@birthday_list.each do |person|
date = Time.new
today = date.strftime("%d %B")
if person[:birthday] == today
print "Today is #{person[:name]}'s birthday!"
end
end
end

end
29 changes: 29 additions & 0 deletions spec/birthday_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
require 'birthday_list'

describe Birthday do

it 'stores first name and birthday' do
birthday_list = Birthday.new
expect(birthday_list.add("Connor", "October")).to eq [{ :name => "Connor", :birthday => "October" }]
end

it "stores second name and birthday" do
birthday_list = Birthday.new
birthday_list.add("Connor", "October")
expect(birthday_list.add("Michael", "April")).to eq [{ :name => "Connor", :birthday => "October" }, { :name => "Michael", :birthday => "April" }]
end

it "prints out each name and birthday on a seperate line" do
birthday_list = Birthday.new
birthday_list.add("Connor", "October")
birthday_list.add("Michael", "April")
expect { birthday_list.print_list }.to output("Connor, October\nMichael, April\n").to_stdout
end

it "finds which dates in the birthday_list array match todays date" do
birthday_list = Birthday.new
birthday_list.add("Connor", "3 October")
birthday_list.add("James", "04 September")
expect { birthday_list.today }.to output("Today is James's birthday!").to_stdout
end

end