3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ftpspec/utils.rb', line 3
def self.convert_to_octal(str)
if str.length != 10
raise
end
octal = Array.new(3)
3.times do |i|
octal[i] = 0
end
3.times do |i|
3.times do |j|
str_key = j + 1 + (3 * i)
octal_key = (i % 3) + (i / 3)
if str[str_key] == "r" then
octal[octal_key] += 4
end
if str[str_key] == "w" then
octal[octal_key] += 2
end
if str[str_key] == "x" then
octal[octal_key] += 1
end
end
end
octal.join("").to_s
end
|