Module: LibPath::Form::Windows::LibPath_Form_Windows_Methods
- Included in:
- LibPath::Form::Windows, LibPath::Form::Windows
- Defined in:
- lib/libpath/form/windows.rb
Overview
Module defining instance functions that will be included and extended into any class or module including/extending module LibPath::Form::Windows
Instance Method Summary collapse
-
#classify_path(path) ⇒ Object
Classifies a path.
-
#name_is_malformed?(name, **options) ⇒ Boolean
Evaluates whether the given name is malformed, according to the given options.
-
#path_is_absolute?(path) ⇒ Boolean
Evaluates whether the given path is absolute, which means it is either rooted (begins with ‘/’) or is homed (is ‘~’ or begins with ‘~/’).
-
#path_is_homed?(path) ⇒ Boolean
Evaluates whether the given path is homed, which means it is ‘~’ or begins with ‘~/’ or ‘~'.
-
#path_is_letter_drived?(path) ⇒ Boolean
Evaluates whether the given path is “letter drived”, which means that it contains a drive specification.
-
#path_is_rooted?(path) ⇒ Boolean
Evalutes whether the given path is rooted, which means it begins with ‘/’.
-
#path_is_UNC?(path) ⇒ Boolean
Evalutes whether the given path is UNC.
Instance Method Details
#classify_path(path) ⇒ Object
Classifies a path
Return
One of :absolute
, :drived
, :homed
, :relative
, :rooted
, for any paths that match precisely those classifications, or nil
if the path is empty
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/libpath/form/windows.rb', line 72 def classify_path path _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG return nil if path.nil? || path.empty? return :homed if path_is_homed? path vol, rem, _ = _Form.get_windows_volume(path) rooted = _Form.char_is_path_name_separator? rem[0] if rooted if vol return :absolute else return :rooted end else if vol return :drived else return :relative end end end |
#name_is_malformed?(name, **options) ⇒ Boolean
Evaluates whether the given name is malformed, according to the given options.
If no options are specified, the only invalid character(s) are: ‘0’
Signature
-
Options:
:reject_path_name_separators
-
(boolean) Reject the path
separator character(s): +'\\'+ and +'/'+
:reject_path_separators
-
(boolean) Reject the path separator
character(s): +';'+
:reject_shell_characters
-
(boolean) Reject the shell
character(s): +'*'+, +'?'+, +'|'+
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/libpath/form/windows.rb', line 122 def name_is_malformed? name, ** _Constants = ::LibPath::Constants::Windows if name if [:reject_shell_characters] return true if name =~ _Constants::InvalidCharacters::Shell::RE end if [:reject_path_separators] return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE end if [:reject_path_name_separators] return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE end return true if name =~ _Constants::InvalidCharacters::Innate::RE if '\\' == name[0] && '\\' == name[1] return true if name !~ /^\\\\[^\\]+\\[^\\]+/ end false else true end end |
#path_is_absolute?(path) ⇒ Boolean
Evaluates whether the given path is absolute, which means it is either rooted (begins with ‘/’) or is homed (is ‘~’ or begins with ‘~/’)
Signature
-
Parameters:
path
-
(String) The path to be evaluated. May not be
nil
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/libpath/form/windows.rb', line 164 def path_is_absolute? path _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG return true if path_is_homed? path vol, rem, _ = _Form.get_windows_volume(path) return false unless vol return false unless rem _Form.char_is_path_name_separator? rem[0] end |
#path_is_homed?(path) ⇒ Boolean
Evaluates whether the given path is homed, which means it is ‘~’ or begins with ‘~/’ or ‘~'
Signature
-
Parameters:
path
-
(String) The path to be evaluated. May not be
nil
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/libpath/form/windows.rb', line 242 def path_is_homed? path _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG return false unless '~' == path[0] if path.size > 1 return _Form.char_is_path_name_separator? path[1] end true end |
#path_is_letter_drived?(path) ⇒ Boolean
Evaluates whether the given path is “letter drived”, which means that it contains a drive specification. Given the two letter sequence ‘X:’ representing any ASCII letter (a-zA-Z) and a colon, this function recognises six sequences: ‘X:’, ‘X:', ’X:/‘, ’\?X:‘, ’\?X:', ‘\?X:/’
Return
- +nil+:: if it is not "drived";
- 2:: it begins with the form +'X:'+
- 3:: it begins with the form +'X:\'+ or +'X:/'+
- 6:: it begins with the form +'\\?\X:'+
- 7:: it begins with the form +'\\?\X:\'+ or +'\\?\X:/'+
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/libpath/form/windows.rb', line 192 def path_is_letter_drived? path _Drive = Internal_::Windows::Drive _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG if path.size >= 2 base_index = 0 if '\\' == path[0] if '\\' == path[1] if '?' == path[2] if '\\' == path[3] base_index = 4 end end end end if ':' == path[base_index + 1] if _Drive.character_is_drive_letter? path[base_index + 0] if _Form.char_is_path_name_separator? path[base_index + 2] return 4 == base_index ? 7 : 3 else return 4 == base_index ? 6 : 2 end end end end nil end |
#path_is_rooted?(path) ⇒ Boolean
Evalutes whether the given path is rooted, which means it begins with ‘/’
Signature
-
Parameters:
path
-
(String) The path to be evaluated. May not be
nil
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/libpath/form/windows.rb', line 265 def path_is_rooted? path _Drive = Internal_::Windows::Drive _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG case path[0] when '/' true when '\\' case path[1] when '\\' vol, rem, _ = _Form.get_windows_volume(path) return false unless vol if rem && _Form.char_is_path_name_separator?(rem[0]) true else false end else true end else if path.size > 2 if ':' == path[1] if _Drive.character_is_drive_letter? path[0] return _Form.char_is_path_name_separator? path[2] end end end false end end |
#path_is_UNC?(path) ⇒ Boolean
Evalutes whether the given path is UNC
Signature
-
Parameters:
path
-
(String) The path to be evaluated. May not be
nil
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/libpath/form/windows.rb', line 319 def path_is_UNC? path _Form = Internal_::Windows::Form Diagnostics.check_string_parameter(path, "path") if $DEBUG return false unless '\\' == path[0] return false unless '\\' == path[1] _, _, frm = _Form.get_windows_volume(path) case frm when :form_2, :form_3, :form_4, :form_5, :form_6 true else false end end |