Class: Playit::Platform
- Inherits:
-
Object
- Object
- Playit::Platform
- Defined in:
- lib/playit/platform.rb
Class Method Summary collapse
-
.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(file) ⇒ Object
Public: opens the JSON file in an editor for you to edit.
-
.open(url) ⇒ 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_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
56 57 58 59 60 61 62 63 64 |
# File 'lib/playit/platform.rb', line 56 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
10 11 12 |
# File 'lib/playit/platform.rb', line 10 def darwin? !!(RUBY_PLATFORM =~ /darwin/) end |
.edit(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.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/playit/platform.rb', line 72 def edit(file) unless $EDITOR.nil? unless windows? system("`echo $EDITOR` #{file} &") else system("start %EDITOR% #{file}") end else system("#{open_command} #{file}") end "Make your edits, and do be sure to save." end |
.open(url) ⇒ 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.
43 44 45 46 47 48 49 50 |
# File 'lib/playit/platform.rb', line 43 def open(url) unless windows? system("#{open_command} '#{url.gsub("\'","'\\\\''")}'") else system("#{open_command} #{url.gsub("\'","'\\\\''")}") end url 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
29 30 31 32 33 34 35 36 37 |
# File 'lib/playit/platform.rb', line 29 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
19 20 21 |
# File 'lib/playit/platform.rb', line 19 def windows? !!(RUBY_PLATFORM =~ /mswin|mingw/) end |