Class: FileName

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy-core/file_info.rb

Overview

Every String could be a Filename but we want a class containing name and path to make some things more explicit.

Direct Known Subclasses

FileInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(the_name, the_path = '') ⇒ FileName

Returns a new instance of FileName.



60
61
62
63
# File 'lib/piggy-core/file_info.rb', line 60

def initialize(the_name, the_path = '')
  @name = the_name
  set_path(the_path)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



57
58
59
# File 'lib/piggy-core/file_info.rb', line 57

def name
  @name
end

#pathObject

Returns the value of attribute path.



58
59
60
# File 'lib/piggy-core/file_info.rb', line 58

def path
  @path
end

Instance Method Details

#extensionObject



81
82
83
# File 'lib/piggy-core/file_info.rb', line 81

def extension
  return name.split('.')[-1]
end

#name_with_pathObject



73
74
75
# File 'lib/piggy-core/file_info.rb', line 73

def name_with_path
  return FilePath.join(path, name)
end

#name_without_extensionObject



77
78
79
# File 'lib/piggy-core/file_info.rb', line 77

def name_without_extension
  return File.basename(name, '.' + extension)
end

#path_sectionsObject



85
86
87
# File 'lib/piggy-core/file_info.rb', line 85

def path_sections
  return FilePath.split(path)
end

#set_path(new_path) ⇒ Object



69
70
71
# File 'lib/piggy-core/file_info.rb', line 69

def set_path(new_path)
  @path = FilePath.intern_path(new_path)
end