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)


85
86
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
# File 'lib/libpath/path/windows.rb', line 85

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



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

def absolute_path
  @absolute_path
end

#compare_pathObject (readonly)

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



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

def compare_path
  @compare_path
end

#directoryObject (readonly)

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



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

def directory
  @directory
end

#directory_partsObject (readonly)

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



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

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)



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

def directory_path
  @directory_path
end

#file_extensionObject (readonly) Also known as: extension

(String) The entry’s file extension



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

def file_extension
  @file_extension
end

#file_full_nameObject (readonly) Also known as: basename

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



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

def file_full_name
  @file_full_name
end

#file_name_onlyObject (readonly) Also known as: stem

(String) The entry’s file stem



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

def file_name_only
  @file_name_only
end

#given_pathObject (readonly)

(String) The path given to initialise the instance



131
132
133
# File 'lib/libpath/path/windows.rb', line 131

def given_path
  @given_path
end

#search_directoryObject (readonly)

(String) The search directory if specified; nil otherwise



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

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



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

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



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

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



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

def search_relative_path
  @search_relative_path
end

#volumeObject (readonly)

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



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

def volume
  @volume
end

Instance Method Details

#to_sObject

(String) String form of path



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

def to_s

	absolute_path
end