27
Sep
09

Shift Subtitle, part 3

Back again for the third time in one day…clearly it’s been a lazy Sunday :]

I decided to implement a SubtitleTime class in order to parse the times for me. This is the class I came up with. There’s probably a cleaner way to split the initial string, but I think this works just fine:

http://charpcfn.pastebin.com/f410f2574

With that class implemented all that’s left is to instantiate the objects and then manipulate them, but wait, there’s a huge problem here. I’ve only accounted for addition to subtitle time. I haven’t even considered subtraction! That’s not good at all. This class is becoming rather verbose, but it’s working well so I’ll just keep going with it. It will get the job done.

Ok at first I had add_hour, add_min, add_sec etc as well as equivalent subtraction methods. But, this would make the main file loop pretty ugly and unreadable. However, the way I have it set up is really inefficient to continuously check the @modifier variable of the class. This will work, it’s just unnecessary steps.

SO after this is all implemented and vaguely tested and broken, my current code is this

http://charpcfn.pastebin.com/f1644cce3

What is wrong with this code:

It pretty much destroys DRY concepts, but I find that’s pretty unavoidable when you first start using a language. Hopefully it will be apparent as I progress in the Ruby language that I follow DRY more closely. This code is pretty verbose and not very well documented. But it’s really not doing anything terribly complicated. Also when you use the params -o add -t 01,001 it will add the milliseconds but not the seconds. I’d figure it out now, but I’m pretty tired.

Things I’ve learned this iteration: I like how easy Ruby classes are. For some reason I just get them more than Python classes. I like the attr_accessor and how that works, it’s pretty neat and useful. The initialize method makes perfect sense and the syntax isn’t terrible. I’d much prefer seeing @var than self.var all over the place.

Until tomorrow!

Advertisements

0 Responses to “Shift Subtitle, part 3”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Challenges

How often I post

September 2009
M T W T F S S
    Oct »
 123456
78910111213
14151617181920
21222324252627
282930  

This is everything


%d bloggers like this: