self-calling method

J

Jonathan Denni

I'm making a program to rename files based on the date/time they were
taken. My camera can take 5 fps, so I want to be able to handle
pictures taken at the same time (since the exif data isn't exact to less
than a second)

this is what I have so far:

---------code---------------

require('rubygems')
require('mini_exiftool')
require('LIB.BBI.rb')


def toBase36(num)
letter='A'
if num<10
num36 = num.to_s
else
while num>10
letter = letter.succ
num = num-1
end
num36=letter
end
return num36
end


def timecode(image)
if MiniExiftool.new(image)['SerialNumber'] == 620315997
owner="JD"
end
time = MiniExiftool.new(image)['DateTimeOriginal']
return to_mcode(time) +'_'+ toBase36(time.strftime('%d').to_i) +
toBase36(time.strftime('%H').to_i) +
time.strftime('%M%S')
end

def check(string)
if FileTest.exist?(string)
strArr = string.split('.')
newString = strArr.first.succ+'.'+strArr.last
check(newString)
else
finalString = string
end
return finalString
end

def renameFilesBTC(files)
files.each do |file|
ext = '.'+file.split('.').last
if file == timecode(file)+ext
puts file+' Already Renamed'
newName = file
elsif file != timecode(file)+ext &&
FileTest.exist?(timecode(file)+ext)
puts "Mulitple Files Same Time"
newName = check(timecode(file)+'1'+ext)
else
puts "Rename"
newName = timecode(file)+ext
end
File.rename(file , newName)
end
end

------------------------------------------------------------------

I'm testing with 3 pictures taken at the same time (actually, 3 copies
of one picture).
The first two rename fine, but the third raises

------------------------------------
TypeError: cannot convert nil into String
from ./renameByDateTime.rb:54:in `rename'
from ./renameByDateTime.rb:54:in `renameFilesBTC'
from ./renameByDateTime.rb:42:in `each'
from ./renameByDateTime.rb:42:in `renameFilesBTC'
from (irb):3
 
E

Erik Veenstra

Replace "check(newString)" by "finalString = check(newString)"
(line 33). Or get rid of "return finalString" (line 37).

What's the advantage of toBase36, compared to the built-in
to_s(36)?

p toBase36(30)
p 30.to_s(36)

gegroet,
Erik V. - http://www.erikveen.dds.nl/
 
S

Simon Schuster

whaaaa, changing the base of a string? this is totally bizarre to me.

003:0> p 10.to_s
"10"
nil
004:0> p 10.to_s(14)
"a"
nil

....
 
P

Phrogz

whaaaa, changing the base of a string? this is totally bizarre to me.

003:0> p 10.to_s
"10"
nil
004:0> p 10.to_s(14)
"a"
nil

Er, you're not changing the base of a string. (That would be something
like 10.to_s.to_base(14).) You're changing the number to be
represented as a string in a specific base, via an argument to the
to_s method.
 
J

Jonathan Denni

Erik said:
Replace "check(newString)" by "finalString = check(newString)"
(line 33). Or get rid of "return finalString" (line 37).

What's the advantage of toBase36, compared to the built-in
to_s(36)?

p toBase36(30)
p 30.to_s(36)

gegroet,
Erik V. - http://www.erikveen.dds.nl/

I simply didn't know about to_s(36)
(I didn't see that in the Pickaxe)

It works! This is great, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top