class PerfectWorld::Clipboard

Writes/Reads data from/to the users clipboard.

Works in graphical environments only. So it is not available via SSH and stuff.

Constants

CMD

Find a working clipboard tool.

COMMANDS

Common clipboard tools.

Public Class Methods

<<(s)
Alias for: write
available?() click to toggle source

Returns true if the clipboard is available, else false.

# File lib/perfect_world/clipboard.rb, line 28
def available?
  ! CMD.nil?
end
read() click to toggle source

Reads a string from the clipboard.

# File lib/perfect_world/clipboard.rb, line 42
def read
  run { `#{CMD[:read]}` }
end
write(s) click to toggle source

Writes a string to the clipboard.

# File lib/perfect_world/clipboard.rb, line 33
def write(s)
  run do
    IO.popen(CMD[:write], 'w') { |io| io << s }
  end
end
Also aliased as: <<

Private Class Methods

run() { || ... } click to toggle source

Wraps the system calls to catch errors.

# File lib/perfect_world/clipboard.rb, line 49
def run
  raise ClipboardNotAvailable unless available?
  yield
rescue SystemCallError, IOError => e
  raise Error, e
end