I have a few ruby scripts that I use to make life a little easier at work. Some of said scripts utilize the clipboard. My work machine is windows and my laptop runs Ubuntu. I’m able to use the same scripts on both computers but I have a few qualms with how I’m doing it.
Right now I’ve got classes for gnome and windows, a clipboard wrapper class to be used by my scripts and a basic (and poorly named) OS class I use to determine which class desktop class to use.
First off, the method I’m using to determine OS is…terrible. Currently I’m doing a string comparison in my OS class, but it doesn’t actually tell me which desktop application I’m actually running, so at the moment it’s just a dirty hack but I’m not sure of the preferred way to do it..
def is_linux
return RUBY_PLATFORM == 'i486-linux'
end
Second, I’m uncomfortable with how I’m importing my desktop specific code in the main clipboard class. Is there a ruby-er way of doing this, or maybe just a smarter way anyone knows of?
class Clipboard
def initialize
os = OS.new
if(os.is_linux)
require 'clipboard/clipboard_gtk'
clipboard = GTKClipboard.new
else
require 'clipboard/clipboard_win32'
clipboard = WinClipboard.new
end
#other stuff
end
Any help would be greatly appreciated!
Download the code: Clipboard Utility
PS: I realize there’s quite a bit of other stuff I need to do to really get this usable, but you have to start somewhere!