Class: LibPath::Path::Windows::ParsedPath

Inherits:
Object
  • Object
show all
Defined in:
lib/libpath/path/windows.rb

Overview

Class representing a parsed path (for Windows)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, search_directory = nil, **options) ⇒ ParsedPath

Initialises an instance from the given path, optional search_directory and options

Signature

  • Parameters:

    • path (String) The path. May not be nil

    • search_directory (String) The search_directory, from which the relative attributes are calculated for the path. May be nil

    • options (Hash) Options

  • Options:

    • ????

  • Exceptions:

    • ArgumentError Raised if path is nil

Raises:

  • (::ArgumentError)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/libpath/path/windows.rb', line 87

def initialize path, search_directory = nil, **options

  raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?

  _Diagnostics    = ::LibPath::Diagnostics
  _Internal_Form  = ::LibPath::Internal_::Windows::Form
  _Util           = ::LibPath::Util::Windows
  _C              = ::LibPath::Path::Windows::ParsedPath::ParsedPath_Constants

  _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)


  abs_path  = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })

  splits    = _Internal_Form.split_path(abs_path)

  _, f1_vol, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, _f7_abs_parts = *splits

  @given_path       = path
  @absolute_path    = abs_path
  @compare_path     = _Util.make_compare_path abs_path, splits: splits
  @volume           = f1_vol
  @directory        = f2_dir
  @directory_path   = "#{f1_vol}#{f2_dir}"
  @directory_parts  = f6_dir_parts

  @file_full_name   = f3_basename
  @file_name_only   = f4_stem
  @file_extension   = f5_ext

  if search_directory

    drp_options                       = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }

    search_directory                  = _Util.make_path_canonical search_directory, make_slashes_canonical: true
    search_directory                  = _Internal_Form.append_trailing_slash search_directory

    @search_directory                 = search_directory
    @search_relative_path             = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
    @search_relative_path             = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
    @search_relative_directory_path   = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, "#{f1_vol}#{f2_dir}", **drp_options)
    @search_relative_directory_parts  = @search_relative_directory_path.split('\\').map { |v| v + '\\' }
  end
end

Instance Attribute Details

#absolute_pathObject (readonly)

(String) The full-path of the instance



135
136
137
# File 'lib/libpath/path/windows.rb', line 135

def absolute_path
  @absolute_path
end

#compare_pathObject (readonly)

(String) A normalised form of #path that can be used in comparisons



137
138
139
# File 'lib/libpath/path/windows.rb', line 137

def compare_path
  @compare_path
end

#directoryObject (readonly)

(String) The entry’s directory (excluding the #drive if on Windows)



141
142
143
# File 'lib/libpath/path/windows.rb', line 141

def directory
  @directory
end

#directory_partsObject (readonly)

([String]) An array of directory parts, where each part ends in the path name separator



147
148
149
# File 'lib/libpath/path/windows.rb', line 147

def directory_parts
  @directory_parts
end

#directory_pathObject (readonly) Also known as: dirname

(String) The full path of the entry’s directory (taking into account the #drive if on Windows)



144
145
146
# File 'lib/libpath/path/windows.rb', line 144

def directory_path
  @directory_path
end

#file_extensionObject (readonly) Also known as: extension

(String) The entry’s file extension



155
156
157
# File 'lib/libpath/path/windows.rb', line 155

def file_extension
  @file_extension
end

#file_full_nameObject (readonly) Also known as: basename

(String) The entry’s file name (combination of #stem + #extension)



149
150
151
# File 'lib/libpath/path/windows.rb', line 149

def file_full_name
  @file_full_name
end

#file_name_onlyObject (readonly) Also known as: stem

(String) The entry’s file stem



152
153
154
# File 'lib/libpath/path/windows.rb', line 152

def file_name_only
  @file_name_only
end

#given_pathObject (readonly)

(String) The path given to initialise the instance



133
134
135
# File 'lib/libpath/path/windows.rb', line 133

def given_path
  @given_path
end

#search_directoryObject (readonly)

(String) The search directory if specified; nil otherwise



158
159
160
# File 'lib/libpath/path/windows.rb', line 158

def search_directory
  @search_directory
end

#search_relative_directory_partsObject (readonly)

([String]) The #directory_parts relative to #search_directory; nil if no search directory specified



164
165
166
# File 'lib/libpath/path/windows.rb', line 164

def search_relative_directory_parts
  @search_relative_directory_parts
end

#search_relative_directory_pathObject (readonly)

(String) The #directory_path relative to #search_directory; nil if no search directory specified



162
163
164
# File 'lib/libpath/path/windows.rb', line 162

def search_relative_directory_path
  @search_relative_directory_path
end

#search_relative_pathObject (readonly)

(String) The #path relative to #search_directory; nil if no search directory specified



160
161
162
# File 'lib/libpath/path/windows.rb', line 160

def search_relative_path
  @search_relative_path
end

#volumeObject (readonly)

(String) The Windows volume, which may be a drive, or a UNC specification



139
140
141
# File 'lib/libpath/path/windows.rb', line 139

def volume
  @volume
end

Instance Method Details

#to_sObject

(String) String form of path



167
168
169
170
# File 'lib/libpath/path/windows.rb', line 167

def to_s

  absolute_path
end