Class: Sanky::PathFinder::Finder
- Inherits:
-
Object
- Object
- Sanky::PathFinder::Finder
- Defined in:
- lib/sanky/pathfinder/finder.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(arguments) ⇒ Finder
constructor
A new instance of Finder.
- #open ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(arguments) ⇒ Finder
Returns a new instance of Finder.
6 7 8 9 |
# File 'lib/sanky/pathfinder/finder.rb', line 6 def initialize(arguments) @found = nil @arguments = arguments end |
Instance Method Details
#convert ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sanky/pathfinder/finder.rb', line 15 def convert @arguments.map! do |original| set = Hash.new() # subsitute windows backslashes for forwardslashes and strip whitespace, add leading forwardslash, and /Volumes prefix set[:original] = original.strip.gsub(/\\/, "/") drive = /.{1,3}:/ # are we talking about sankynet or sanky direct drives here? let's try both. if original.match(drive) set[:sanky_net] = set[:original].sub(drive, "/Volumes/SankyNet Drive") set[:sanky_direct] = set[:original].sub(drive, "/Volumes/Sanky Direct Drive/Sanky Shared") else set[:volume] = set[:original].sub(/^(?!\/Volumes)/i, "/Volumes/") end set.map { |key, value| value.gsub!(/\/\//, "/") } set end self end |
#open ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sanky/pathfinder/finder.rb', line 39 def open @arguments.each do |target| target.each do |drive, file| unless @found begin # pipe STDERR to dev null in favor of custom prompt `open -g '#{file}' > /dev/null 2>/dev/null` ensure if $? == 0 @found = true puts "Opening the file in the background...".yellow else puts "Failed to find #{file}!".red puts "Trying another likely location...".red end end end end puts "Hope you got lucky!".green end end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/sanky/pathfinder/finder.rb', line 11 def to_s @arguments end |