Class: Jello::Pasteboard
- Inherits:
-
Object
- Object
- Jello::Pasteboard
- Defined in:
- lib/jello/pasteboard.rb
Constant Summary collapse
- General =
A pasteboard that stores general text
new :board => :general
- Ruler =
Unknown
new :board => :ruler
- Find =
A pasteboard that stores the text used in find dialogues
new :board => :find
- Font =
Unknown
new :board => :font
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
The type of board to connect to.
-
#current ⇒ Object
Returns the value of attribute current.
-
#format ⇒ Object
The type of data to request from the board.
-
#last ⇒ Object
The last paste recognized by the pasteboard.
Instance Method Summary collapse
-
#gets ⇒ Object
This method gets the latest paste from the selected pasteboard, of the selected format (if possible - see ‘#format`).
-
#initialize(options = {}) {|_self| ... } ⇒ Pasteboard
constructor
This creates a new Pasteboard instance, connected to one of the available Mac OS X pasteboards.
-
#puts(something) ⇒ Object
This method puts a new entry into the selected pasteboard.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Pasteboard
This creates a new Pasteboard instance, connected to one of the available Mac OS X pasteboards. You shouldn’t use this directly - use one of the pre-defined constants instead.
51 52 53 54 55 56 57 58 59 |
# File 'lib/jello/pasteboard.rb', line 51 def initialize = {} @board ||= [:board] || :general @format ||= [:format] || :ascii yield self if block_given? @current = "" @last = "" end |
Instance Attribute Details
#board ⇒ Object (readonly)
The type of board to connect to. Available are the following:
- :general [default]
- :ruler
- :find
- :font
OS X offers various pasteboards for use, depending on what you want to access. They’re synced across the entire system. More information is available under ‘man pbpaste`.
20 21 22 |
# File 'lib/jello/pasteboard.rb', line 20 def board @board end |
#current ⇒ Object
Returns the value of attribute current.
42 43 44 |
# File 'lib/jello/pasteboard.rb', line 42 def current @current end |
#format ⇒ Object
The type of data to request from the board. Available are the following:
- :ascii [default]
- :rtf (Rich Text)
- :ps (PostScript)
You’re not guaranteed to receive that type, however - you’ll receive it if it’s available, otherwise you’ll receive the first in the above list that is available. More information is available under ‘man pbpaste`.
34 35 36 |
# File 'lib/jello/pasteboard.rb', line 34 def format @format end |
#last ⇒ Object
The last paste recognized by the pasteboard. If you modify the contents of the pasteboard, you can save processing time by also updating this property with said contents, preventing an extra loop.
40 41 42 |
# File 'lib/jello/pasteboard.rb', line 40 def last @last end |
Instance Method Details
#gets ⇒ Object
This method gets the latest paste from the selected pasteboard, of the selected format (if possible - see ‘#format`).
67 68 69 70 71 72 |
# File 'lib/jello/pasteboard.rb', line 67 def gets @last = @current command = 'pbpaste' command << " -pboard #{@board}" if @board @current = %x[#{command}].chomp end |
#puts(something) ⇒ Object
This method puts a new entry into the selected pasteboard. Format is automatically deduced from the headers of your string (see ‘man pbpaste` for more info.)
80 81 82 83 84 85 86 87 88 |
# File 'lib/jello/pasteboard.rb', line 80 def puts something command = 'pbcopy' command << " -pboard #{@board}" if @board command << " -Prefer #{@format}" if @format out = IO::popen command, 'w+' out.print something out.close something end |