# Making a class with built-in checks on success

**URL:** <https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717>\
**Category:** Ruby\
**Created:** [April 11, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717 "2007-04-11T20:52:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 11, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717/1 "2007-04-11T20:52:43Z")

</div>

Hello,  
I’ve been using an image conversion tool here in my department for many  
years, and, I’d like to create a Ruby class for it that I can call on in  
my scripts. I use this tool usually to convert either PDF or EPS  
original files to a variety of bitmap formats. Sometimes I might have a  
problem with the software converting a particular PDF or EPS file,  
usually because of some anomaly in the original file. So, in my Ruby  
scripts, I’d like to tell my script to use the other source format if  
the one doesn’t work, i.e, use the EPS original instead of the PDF if  
the PDF doesn’t work, or vice-versa.

Anyway, can someone suggest some kind of success check in this class?  
How could I include, in each of my defs below, some sort of  
error-checking? If I just put an “if Alchemy.tiff == true,” it’s too  
late. The file might’ve already failed.

I’m using it in script like this:  
…  
Alchemy.tiff pdffile  
…  
Alchemy.png pdffile  
…

Thanks a lot. I’m totally new to this class business, but, I can see  
that it’s part of the gold that’s in Ruby.

Peter

class Alchemy  
def initialize(file)  
@file = file  
end

def Alchemy.tiff(file)  
`alchemy #{file} -t1 -Zc1 -Zm2 -Za4 -Zd 300 300 -o`  
end  
def Alchemy.tiffbw(file)  
`alchemy #{file} -t204 -Zc1 -Zm2 -Za4 -Zd 300 300 -o`  
end  
def Alchemy.png(file)  
`alchemy #{file} ---n9 -Zc1 -Zm2 -Za4 -Zd 100 100 -o`  
end  
end

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 11, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717/2 "2007-04-11T22:10:43Z")

</div>

On Thu, Apr 12, 2007 at 03:52:47AM +0900, Peter B. wrote:

> Anyway, can someone suggest some kind of success check in this class?

The command’s exit status should be set in $? after calling the command  
in  
backticks.

ri Process::Status

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 11, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717/3 "2007-04-11T22:16:02Z")

</div>

Brian C. wrote:

> On Thu, Apr 12, 2007 at 03:52:47AM +0900, Peter B. wrote:
> 
> > Anyway, can someone suggest some kind of success check in this class?
> 
> The command’s exit status should be set in $? after calling the command  
> in  
> backticks.
> 
> ri Process::Status

Wow. Sounds simple. I’ll play with that. Thanks!

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 12, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/making-a-class-with-built-in-checks-on-success/91717/4 "2007-04-12T13:40:23Z")

</div>

On Wednesday 11 April 2007 20:16, Peter B. wrote:

> Wow. Sounds simple. I’ll play with that. Thanks!  
> check exit status, or use File to check if file exists after conversion  
> good idea would be to use Exceptions and retry
