Class: Boom::Platform
- Inherits:
-
Object
- Object
- Boom::Platform
- Defined in:
- lib/kaboom/platform.rb
Class Method Summary collapse
-
.copy(item) ⇒ Object
Public: copies a given Item’s value to the clipboard.
-
.copy_command ⇒ Object
Public: returns the command used to copy a given Item’s value to the clipboard for the current platform.
-
.darwin? ⇒ Boolean
Public: tests if currently running on darwin.
-
.edit(json_file) ⇒ Object
Public: opens the JSON file in an editor for you to edit.
-
.open(item) ⇒ Object
Public: opens a given Item’s value in the browser.
-
.open_command ⇒ Object
Public: returns the command used to open a file or URL for the current platform.
-
.windows? ⇒ Boolean
Public: tests if currently running on windows.
Class Method Details
.copy(item) ⇒ Object
Public: copies a given Item’s value to the clipboard. This method is designed to handle multiple platforms.
Returns the String value of the Item.
77 78 79 80 |
# File 'lib/kaboom/platform.rb', line 77 def copy(item) IO.popen(copy_command,"w") {|cc| cc.write(item.value)} item.value end |
.copy_command ⇒ Object
Public: returns the command used to copy a given Item’s value to the clipboard for the current platform.
Returns a String with the bin
63 64 65 66 67 68 69 70 71 |
# File 'lib/kaboom/platform.rb', line 63 def copy_command if darwin? 'pbcopy' elsif windows? 'clip' else 'xclip -selection clipboard' end end |
.darwin? ⇒ Boolean
Public: tests if currently running on darwin.
Returns true if running on darwin (MacOS X), else false
16 17 18 |
# File 'lib/kaboom/platform.rb', line 16 def darwin? !!(RUBY_PLATFORM =~ /darwin/) end |
.edit(json_file) ⇒ Object
Public: opens the JSON file in an editor for you to edit. Uses the $EDITOR environment variable, or %EDITOR% on Windows for editing. This method is designed to handle multiple platforms. If $EDITOR is nil, try to open using the open_command.
Returns a String with a helpful message.
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kaboom/platform.rb', line 88 def edit(json_file) unless $EDITOR.nil? unless windows? system("`echo $EDITOR` #{json_file} &") else system("start %EDITOR% #{json_file}") end else system("#{open_command} #{json_file}") end "Make your edits, and do be sure to save." end |
.open(item) ⇒ Object
Public: opens a given Item’s value in the browser. This method is designed to handle multiple platforms.
Returns a String of the Item value.
49 50 51 52 53 54 55 56 57 |
# File 'lib/kaboom/platform.rb', line 49 def open(item) unless windows? system("#{open_command} '#{item.url.gsub("\'","'\\\\''")}'") else system("#{open_command} #{item.url.gsub("\'","'\\\\''")}") end item.value end |
.open_command ⇒ Object
Public: returns the command used to open a file or URL for the current platform.
Currently only supports MacOS X and Linux with ‘xdg-open`.
Returns a String with the bin
35 36 37 38 39 40 41 42 43 |
# File 'lib/kaboom/platform.rb', line 35 def open_command if darwin? 'open' elsif windows? 'start' else 'xdg-open' end end |
.windows? ⇒ Boolean
Public: tests if currently running on windows.
Apparently Windows RUBY_PLATFORM can be ‘win32’ or ‘mingw32’
Returns true if running on windows (win32/mingw32), else false
25 26 27 |
# File 'lib/kaboom/platform.rb', line 25 def windows? !!(RUBY_PLATFORM =~ /mswin|mingw/) end |