Sha256: 0de8ee0cd4e8c0610ba88b7a81a347cda4f6980fe2ab5cd7590db221117336e4
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
# coding: utf-8 # Platform is a centralized point to shell out platform specific functionality # like clipboard access or commands to open URLs. # # # Clipboard is a centralized point to shell out to each individual platform's # clipboard, pasteboard, or whatever they decide to call it. # module Boom class Platform class << self # Public: tests if currently running on darwin. # # Returns true if running on darwin (MacOS X), else false def darwin? !!(RUBY_PLATFORM =~ /darwin/) end # 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 def open_command darwin? ? 'open' : 'xdg-open' end # 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 def open(item) `#{open_command} '#{item.url.gsub("\'","\\'")}'` "Boom! We just opened #{item.value} for you." end # 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 def copy(item) copy_command = darwin? ? "pbcopy" : "xclip -selection clipboard" Kernel.system("echo '#{item.value.gsub("\'","\\'")}' | tr -d \"\n\" | #{copy_command}") "Boom! We just copied #{item.value} to your clipboard." end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
boom-0.2.0 | lib/boom/platform.rb |
boom-0.1.2 | lib/boom/platform.rb |