Class: Mj::AlternativeFile::CurrentFile
- Inherits:
-
Object
- Object
- Mj::AlternativeFile::CurrentFile
show all
- Defined in:
- lib/mj/alternative_file/current_file.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CurrentFile.
8
9
10
|
# File 'lib/mj/alternative_file/current_file.rb', line 8
def initialize(path)
@path = Pathname.new(path.to_s)
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
6
7
8
|
# File 'lib/mj/alternative_file/current_file.rb', line 6
def path
@path
end
|
Instance Method Details
#end_with?(*args) ⇒ Boolean
44
45
46
|
# File 'lib/mj/alternative_file/current_file.rb', line 44
def end_with?(*args)
to_s.end_with?(*args)
end
|
#exist? ⇒ Boolean
76
77
78
|
# File 'lib/mj/alternative_file/current_file.rb', line 76
def exist?
::File.exist?(to_s)
end
|
#extension ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/mj/alternative_file/current_file.rb', line 16
def extension
parts = split(".")
if parts.length > 1
parts.last
end
end
|
#gsub(find, replace) ⇒ Object
64
65
66
|
# File 'lib/mj/alternative_file/current_file.rb', line 64
def gsub(find, replace)
new(to_s.gsub(find, replace))
end
|
#join(other_part) ⇒ Object
68
69
70
|
# File 'lib/mj/alternative_file/current_file.rb', line 68
def join(other_part)
new(@path.join(other_part.to_s))
end
|
#match?(*args) ⇒ Boolean
56
57
58
|
# File 'lib/mj/alternative_file/current_file.rb', line 56
def match?(*args)
to_s.match?(*args)
end
|
#name ⇒ Object
32
33
34
|
# File 'lib/mj/alternative_file/current_file.rb', line 32
def name
to_s.split("/").last
end
|
#path_without_extension ⇒ Object
28
29
30
|
# File 'lib/mj/alternative_file/current_file.rb', line 28
def path_without_extension
sub(/.#{extension}$/, "")
end
|
#prefix_with(prefix) ⇒ Object
72
73
74
|
# File 'lib/mj/alternative_file/current_file.rb', line 72
def prefix_with(prefix)
new(prefix).join(self)
end
|
#split(char = "/") ⇒ Object
36
37
38
|
# File 'lib/mj/alternative_file/current_file.rb', line 36
def split(char = "/")
to_s.split(char)
end
|
#start_with?(*args) ⇒ Boolean
40
41
42
|
# File 'lib/mj/alternative_file/current_file.rb', line 40
def start_with?(*args)
to_s.start_with?(*args)
end
|
#sub(find, replace) ⇒ Object
60
61
62
|
# File 'lib/mj/alternative_file/current_file.rb', line 60
def sub(find, replace)
new(to_s.sub(find, replace))
end
|
#to_s ⇒ Object
12
13
14
|
# File 'lib/mj/alternative_file/current_file.rb', line 12
def to_s
path.to_s
end
|
#trim_slashes ⇒ Object
24
25
26
|
# File 'lib/mj/alternative_file/current_file.rb', line 24
def trim_slashes
to_s.gsub("//", "/").sub(%r{^/}, "").sub(%r{/$}, "")
end
|
#without_prefix(prefix) ⇒ Object
48
49
50
|
# File 'lib/mj/alternative_file/current_file.rb', line 48
def without_prefix(prefix)
sub(/^#{prefix}/, "")
end
|
#without_suffix(suffix) ⇒ Object
52
53
54
|
# File 'lib/mj/alternative_file/current_file.rb', line 52
def without_suffix(suffix)
sub(/#{suffix}$/, "")
end
|