Class: SingleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/file_obj.rb

Overview

Global file objects $file and $files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SingleFile

Returns a new instance of SingleFile.



7
8
9
# File 'lib/file_obj.rb', line 7

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Full file path e.g. “src/main.c”



5
6
7
# File 'lib/file_obj.rb', line 5

def path
  @path
end

Instance Method Details

#dirObject

the directory of the file e.g. if the file is “src/main.c”, dir will be “src”



28
29
30
# File 'lib/file_obj.rb', line 28

def dir
  File.dirname(@path)
end

#extObject

the file extension



22
23
24
# File 'lib/file_obj.rb', line 22

def ext
  File.extname(@path)
end

#full_nameObject

the file name and extension



17
18
19
# File 'lib/file_obj.rb', line 17

def full_name
  File.basename(@path)
end

#nameObject

the name of the file, without extension



12
13
14
# File 'lib/file_obj.rb', line 12

def name
  File.basename(@path, ".*")
end

#to_sObject

will return path



33
34
35
# File 'lib/file_obj.rb', line 33

def to_s
  @path
end