Class: LibPath::Path::Windows::ParsedPath
- Inherits:
-
Object
- Object
- LibPath::Path::Windows::ParsedPath
- Defined in:
- lib/libpath/path/windows.rb
Overview
Class representing a parsed path (for Windows)
Instance Attribute Summary collapse
-
#absolute_path ⇒ Object
readonly
(String) The full-path of the instance.
-
#compare_path ⇒ Object
readonly
(String) A normalised form of #path that can be used in comparisons.
-
#directory ⇒ Object
readonly
(String) The entry’s directory (excluding the #drive if on Windows).
-
#directory_parts ⇒ Object
readonly
([String]) An array of directory parts, where each part ends in the path name separator.
-
#directory_path ⇒ Object
(also: #dirname)
readonly
(String) The full path of the entry’s directory (taking into account the #drive if on Windows).
-
#file_extension ⇒ Object
(also: #extension)
readonly
(String) The entry’s file extension.
-
#file_full_name ⇒ Object
(also: #basename)
readonly
(String) The entry’s file name (combination of #stem + #extension).
-
#file_name_only ⇒ Object
(also: #stem)
readonly
(String) The entry’s file stem.
-
#given_path ⇒ Object
readonly
(String) The path given to initialise the instance.
-
#search_directory ⇒ Object
readonly
(String) The search directory if specified;
nilotherwise. -
#search_relative_directory_parts ⇒ Object
readonly
([String]) The #directory_parts relative to #search_directory;
nilif no search directory specified. -
#search_relative_directory_path ⇒ Object
readonly
(String) The #directory_path relative to #search_directory;
nilif no search directory specified. -
#search_relative_path ⇒ Object
readonly
(String) The #path relative to #search_directory;
nilif no search directory specified. -
#volume ⇒ Object
readonly
(String) The Windows volume, which may be a drive, or a UNC specification.
Instance Method Summary collapse
-
#initialize(path, search_directory = nil, **options) ⇒ ParsedPath
constructor
Initialises an instance from the given
path, optionalsearch_directoryand options. -
#to_s ⇒ Object
(String) String form of path.
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 benil -
search_directory(String) The search_directory, from which the relative attributes are calculated for the path. May benil -
options(Hash) Options
-
-
Options:
-
????
-
-
Exceptions:
-
ArgumentErrorRaised ifpathisnil
-
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, ** 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.(, known: _C::INIT_VALID_OPTIONS) abs_path = _Util.make_path_absolute(path, make_canonical: true, **.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 = .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, **) @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}", **) @search_relative_directory_parts = @search_relative_directory_path.split('\\').map { |v| v + '\\' } end end |
Instance Attribute Details
#absolute_path ⇒ Object (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_path ⇒ Object (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 |
#directory ⇒ Object (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_parts ⇒ Object (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_path ⇒ Object (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_extension ⇒ Object (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_name ⇒ Object (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_only ⇒ Object (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_path ⇒ Object (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_directory ⇒ Object (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_parts ⇒ Object (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_path ⇒ Object (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_path ⇒ Object (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 |
#volume ⇒ Object (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_s ⇒ Object
(String) String form of path
165 166 167 168 |
# File 'lib/libpath/path/windows.rb', line 165 def to_s absolute_path end |