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
71 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 |
# File 'lib/libpath/form/windows.rb', line 71 def classify_path path Diagnostics.check_string_parameter(path, "path") if $DEBUG return nil if path.nil? || path.empty? return :homed if path_is_homed? path vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path) rooted = Internal_::Windows::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): +'*'+, +'?'+, +'|'+
119 120 121 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 |
# File 'lib/libpath/form/windows.rb', line 119 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
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/libpath/form/windows.rb', line 161 def path_is_absolute? path Diagnostics.check_string_parameter(path, "path") if $DEBUG return true if path_is_homed? path vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path) return false unless vol return false unless rem Internal_::Windows::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
234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/libpath/form/windows.rb', line 234 def path_is_homed? path Diagnostics.check_string_parameter(path, "path") if $DEBUG return false unless '~' == path[0] if path.size > 1 return Internal_::Windows::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:/'+
187 188 189 190 191 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 |
# File 'lib/libpath/form/windows.rb', line 187 def path_is_letter_drived? path 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 Internal_::Windows::Drive.character_is_drive_letter? path[base_index + 0] if Internal_::Windows::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
255 256 257 258 259 260 261 262 263 264 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 |
# File 'lib/libpath/form/windows.rb', line 255 def path_is_rooted? path Diagnostics.check_string_parameter(path, "path") if $DEBUG case path[0] when '/' true when '\\' case path[1] when '\\' vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path) return false unless vol if rem && Internal_::Windows::Form.char_is_path_name_separator?(rem[0]) true else false end else true end else if path.size > 2 if ':' == path[1] if Internal_::Windows::Drive.character_is_drive_letter? path[0] return Internal_::Windows::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
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/libpath/form/windows.rb', line 306 def path_is_UNC? path Diagnostics.check_string_parameter(path, "path") if $DEBUG return false unless '\\' == path[0] return false unless '\\' == path[1] _, _, frm = Internal_::Windows::Form.get_windows_volume(path) case frm when :form_2, :form_3, :form_4, :form_5, :form_6 true else false end end |