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

Improvements #9

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion birthdays.example.txt

This file was deleted.

17 changes: 17 additions & 0 deletions birthdays.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
01 :
{
01 : [ "elvina.slovak" ]
},

02 :
{
02 : [ "john.doe", "jane.doe" ],
28 : [ "chris.nolan" ],
},

04 :
{
15 : [ "erwin.down", "leora.pontious", "randy.young" ]
}
}
9 changes: 9 additions & 0 deletions birthdays.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
01 :
01 : [ "elvina.slovak" ]

02 :
02 : [ "john.doe", "jane.doe" ]
28 : [ "chris.nolan" ]

04
15 : [ "erwin.down", "leora.pontious", "randy.young" ]
9 changes: 4 additions & 5 deletions lib/birthday_reader.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
require 'yaml'

class BirthdayReader
def self.get_birthdays(file_path)
birthdays = []
if File.exist?(file_path)
file = File.new(file_path, 'r')
file.each_line do |line|
birthdays << line.chomp.split
end
file.close
bday_list = YAML.load_file(file_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this class is to read birthdays only, I don't think we should return only the birthdays according to Time.now, instead we should return all of them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary reason I switched to a structured format for the database was to drill down to the exact date to fetch all the birthdays on the day. What would be the use case to have return all the birthdays together? It would just use more memory (for no particular gain, whatsoever) IMHO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not against the structuring.

What I am saying is that the purpose of the function is to read birthdays. It is not to read and filter. That is why I think we should not filter the birthdays here.

And because we are just managing strings of birthdays I guess memory is not a concern.

birthdays = bday_list[Time.now.month][Time.now.day]
end
return birthdays
end
Expand Down