Posts Tagged ‘second thoughts

28
Sep
09

Shift Subtitle, part 4

Well now it’s just a matter of debugging my code. I suppose writing tests would be the ideal thing to do, but I think there is just a stupid typo in there somewhere that I’ll have to look for.

Ok. I had some ideas while I started working. It pretty much went like this:

  1. Reading in the times is working but assumes they are always in full format (ie 00:00:00,000) and does not handle 00,000 situations.
  2. the to_s method is terrible, I’ve only used sprintf once or twice in PHP so it’s no wonder I didn’t think of it right off. That cleaned it up quite a bit.

So after figuring out a way to read in the times and account for partial time entries, I did a bit of refactoring and testing and found out that it’s working now, horray!
I just thought of another, probably easier way this could have been accomplished. If I had taken the file times, converted them to milliseconds and then added/subtracted the converted input times then spit them back out as HH:MM:SS,mmm it might have been less verbose code, but I think this was a good exercise to learn a bit about Ruby classes. And anyways, my code works and that’s all that counts, right?

http://charpcfn.pastebin.com/f594e4212

That’s my submitted code!

Can’t wait for the next challenge :]

edit: If I find myself with some extra time I will probably go back and write some unit tests and maybe try making it a Gem as practice since there is still a while before the next challenge starts.




Challenges

How often I post

July 2017
M T W T F S S
« Dec    
 12
3456789
10111213141516
17181920212223
24252627282930
31  

This is everything