tbpgr/tbpgr_utils

View on GitHub
lib/open_classes/string/winpath_to_cygwinpath.rb

Summary

Maintainability
A
20 mins
Test Coverage
# encoding: utf-8

class String
  # convert windows path to cygwin path
  #
  # ==== Examples
  #
  #   'C:\hoge\hoge.txt'.winpath_to_cygwinpath # => '/cygdrive/c/hoge/hoge.txt'
  #
  def winpath_to_cygwinpath
    return self unless match(/\w:\\/)
    drive = scan(/(\w):\\/).first.first.downcase
    dir_file = scan(/\w:\\(.*)/).first.first.gsub('\\', '/')
    "/cygdrive/#{drive}/#{dir_file}"
  end
end