Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/cxxproject/ext/file.rb
Constant Summary collapse
- SLASH =
'/'
Class Method Summary collapse
- .add_prefix(prefix, file) ⇒ Object
- .is_absolute?(filename) ⇒ Boolean
- .rel_from_to_project(from, to, endWithSlash = true) ⇒ Object
Class Method Details
.add_prefix(prefix, file) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/cxxproject/ext/file.rb', line 49 def self.add_prefix(prefix, file) if not prefix or is_absolute?(file) file else prefix + file end end |
.is_absolute?(filename) ⇒ Boolean
7 8 9 |
# File 'lib/cxxproject/ext/file.rb', line 7 def self.is_absolute?(filename) filename[0] == SLASH or filename[1] == ':' end |
.rel_from_to_project(from, to, endWithSlash = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cxxproject/ext/file.rb', line 11 def self.rel_from_to_project(from,to,endWithSlash = true) return nil if from.nil? or to.nil? toSplitted = to.split('/') fromSplitted = from.split('/') max = [toSplitted.length, fromSplitted.length].min return nil if max < 1 i = 0 # path letter in windows may be case different if toSplitted[0].length > 1 and fromSplitted[0].length > 1 i = 1 if toSplitted[0][1] == ':' and fromSplitted[0][1] == ':' and toSplitted[0].swapcase[0] == fromSplitted[0][0] end while i < max break if toSplitted[i] != fromSplitted[i] i += 1 end j = i res = [] while i < fromSplitted.length res << ".." i += 1 end while j < toSplitted.length res << toSplitted[j] j += 1 end if res.length == 0 return "" end res = res.join('/') res += "/" if endWithSlash res end |