Class: Boom::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/boom/platform.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
50
51
# File 'lib/boom/platform.rb', line 45

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

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

  "Boom! We just copied #{item.value} to your clipboard."
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/boom/platform.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/boom/platform.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/boom/platform.rb', line 27

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