Class: Zooline::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/zooline/plateform.rb

Class Method Summary collapse

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 a String explaining what was done



45
46
47
48
49
# File 'lib/zooline/plateform.rb', line 45

def copy(item)
  copy_command = darwin? ? "pbcopy" : "xclip -selection clipboard"

  `echo '#{item.gsub("\'","\\'")}' | tr -d "\n" | #{copy_command}`
end

.darwin?Boolean

Public: tests if currently running on darwin.

Returns true if running on darwin (MacOS X), else false

Returns:

  • (Boolean)


17
18
19
# File 'lib/zooline/plateform.rb', line 17

def darwin?
  !!(RUBY_PLATFORM =~ /darwin/)
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 explaining what was done



35
36
37
38
39
# File 'lib/zooline/plateform.rb', line 35

def open(item)
  `#{open_command} '#{item.url.gsub("\'","\\'")}'`

  "Boom! We just opened #{item.value} for you."
end

.open_commandObject

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



27
28
29
# File 'lib/zooline/plateform.rb', line 27

def open_command
  darwin? ? 'open' : 'xdg-open'
end