Class: Diakonos::ClipboardOSX
Overview
Same interface as Diakonos::Clipboard, except interacts with pbcopy and pbpaste on OSX
Instance Method Summary collapse
-
#add_clip(text) ⇒ Object
True iff a clip was added.
-
#append_to_clip(text) ⇒ Object
Appends the lines to the current clip.
-
#clip ⇒ Object
——————————.
-
#each ⇒ Object
no-op.
-
#initialize ⇒ ClipboardOSX
constructor
A new instance of ClipboardOSX.
-
#send_to_pbcopy(text) ⇒ Object
True iff some text was copied to pbcopy.
-
#write_to_clip_file(text) ⇒ Object
TODO: DRY this up with other Clipboard classes.
Constructor Details
#initialize ⇒ ClipboardOSX
Returns a new instance of ClipboardOSX.
7 8 |
# File 'lib/diakonos/clipboard-osx.rb', line 7 def initialize end |
Instance Method Details
#add_clip(text) ⇒ Object
Returns true iff a clip was added.
37 38 39 |
# File 'lib/diakonos/clipboard-osx.rb', line 37 def add_clip(text) send_to_pbcopy text end |
#append_to_clip(text) ⇒ Object
Appends the lines to the current clip. If no current clip, then a new clip is created.
49 50 51 52 53 54 55 56 |
# File 'lib/diakonos/clipboard-osx.rb', line 49 def append_to_clip(text) return false if text.nil? last_clip = clip last_clip.pop if last_clip[-1] == "" send_to_pbcopy last_clip + text end |
#clip ⇒ Object
31 32 33 |
# File 'lib/diakonos/clipboard-osx.rb', line 31 def clip `pbpaste`.split( "\n", -1 ) end |
#send_to_pbcopy(text) ⇒ Object
Returns true iff some text was copied to pbcopy.
11 12 13 14 15 16 17 18 |
# File 'lib/diakonos/clipboard-osx.rb', line 11 def send_to_pbcopy(text) return false if text.nil? clip_filename = write_to_clip_file( text.join( "\n" ) ) `pbcopy < #{clip_filename}` true end |
#write_to_clip_file(text) ⇒ Object
TODO: DRY this up with other Clipboard classes
21 22 23 24 25 26 27 |
# File 'lib/diakonos/clipboard-osx.rb', line 21 def write_to_clip_file(text) clip_filename = $diakonos.diakonos_home + "/clip.txt" File.open( clip_filename, "w" ) do |f| f.print text end clip_filename end |