libpath-ruby 0.2.2 → 0.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +33 -0
  3. data/README.md +25 -8
  4. data/examples/path_from_arg0.md +43 -43
  5. data/examples/path_from_arg0.rb +25 -23
  6. data/lib/libpath/constants/unix.rb +74 -74
  7. data/lib/libpath/constants/windows.rb +75 -75
  8. data/lib/libpath/constants.rb +20 -20
  9. data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +118 -118
  15. data/lib/libpath/form/windows.rb +228 -214
  16. data/lib/libpath/form.rb +20 -21
  17. data/lib/libpath/internal_/array.rb +57 -57
  18. data/lib/libpath/internal_/platform.rb +30 -31
  19. data/lib/libpath/internal_/string.rb +25 -20
  20. data/lib/libpath/internal_/unix/form.rb +124 -119
  21. data/lib/libpath/internal_/windows/drive.rb +80 -75
  22. data/lib/libpath/internal_/windows/form.rb +205 -194
  23. data/lib/libpath/libpath.rb +4 -1
  24. data/lib/libpath/path/unix.rb +120 -118
  25. data/lib/libpath/path/windows.rb +126 -124
  26. data/lib/libpath/path.rb +21 -21
  27. data/lib/libpath/util/unix.rb +261 -261
  28. data/lib/libpath/util/windows.rb +403 -403
  29. data/lib/libpath/util.rb +20 -20
  30. data/lib/libpath/version.rb +25 -26
  31. data/lib/libpath.rb +1 -1
  32. data/test/performance/benchmark_drive_letter.rb +50 -10
  33. data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
  34. data/test/performance/benchmark_rindex2.rb +56 -48
  35. data/test/performance/benchmark_split.rb +16 -10
  36. data/test/unit/compare/ts_all.rb +4 -4
  37. data/test/unit/equate/ts_all.rb +4 -4
  38. data/test/unit/equate/unix/ts_all.rb +4 -4
  39. data/test/unit/equate/windows/ts_all.rb +4 -4
  40. data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
  41. data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
  42. data/test/unit/exceptions/ts_all.rb +4 -4
  43. data/test/unit/form/tc_absolute_functions.rb +242 -240
  44. data/test/unit/form/ts_all.rb +4 -4
  45. data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
  46. data/test/unit/form/unix/ts_all.rb +4 -4
  47. data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
  48. data/test/unit/form/windows/ts_all.rb +4 -4
  49. data/test/unit/internal_/tc_array.rb +36 -32
  50. data/test/unit/internal_/ts_all.rb +4 -4
  51. data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
  52. data/test/unit/internal_/unix/form/ts_all.rb +4 -4
  53. data/test/unit/internal_/unix/tc_split_path.rb +387 -384
  54. data/test/unit/internal_/unix/ts_all.rb +4 -4
  55. data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
  56. data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
  57. data/test/unit/internal_/windows/form/ts_all.rb +4 -4
  58. data/test/unit/internal_/windows/tc_split_path.rb +874 -869
  59. data/test/unit/internal_/windows/ts_all.rb +4 -4
  60. data/test/unit/parse/ts_all.rb +4 -4
  61. data/test/unit/path/tc_path.rb +732 -732
  62. data/test/unit/path/ts_all.rb +4 -4
  63. data/test/unit/path/unix/tc_path.rb +544 -540
  64. data/test/unit/path/unix/ts_all.rb +4 -4
  65. data/test/unit/path/windows/tc_path.rb +608 -603
  66. data/test/unit/path/windows/ts_all.rb +4 -4
  67. data/test/unit/tc_version.rb +25 -22
  68. data/test/unit/ts_all.rb +4 -4
  69. data/test/unit/util/tc_combine_paths.rb +110 -105
  70. data/test/unit/util/tc_derive_relative_path.rb +8 -3
  71. data/test/unit/util/tc_make_path_canonical.rb +142 -138
  72. data/test/unit/util/ts_all.rb +4 -4
  73. data/test/unit/util/unix/tc_combine_paths.rb +38 -34
  74. data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
  75. data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
  76. data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
  77. data/test/unit/util/unix/ts_all.rb +4 -4
  78. data/test/unit/util/windows/tc_combine_paths.rb +82 -77
  79. data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
  80. data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
  81. data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
  82. data/test/unit/util/windows/ts_all.rb +4 -4
  83. metadata +9 -8
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: libpath/path/unix.rb
3
+ # File: libpath/path/unix.rb
4
4
  #
5
- # Purpose: LibPath::Path::Unix module
5
+ # Purpose: LibPath::Path::Unix module
6
6
  #
7
- # Created: 21st January 2019
8
- # Updated: 16th April 2019
7
+ # Created: 21st January 2019
8
+ # Updated: 7th April 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/libpath.Ruby
10
+ # Home: http://github.com/synesissoftware/libpath.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -44,7 +45,6 @@
44
45
  # ######################################################################## #
45
46
 
46
47
 
47
-
48
48
  =begin
49
49
  =end
50
50
 
@@ -52,119 +52,121 @@ require 'libpath/diagnostics'
52
52
  require 'libpath/internal_/unix/form'
53
53
  require 'libpath/util/unix'
54
54
 
55
- module LibPath # :nodoc:
56
- module Path # :nodoc:
57
- module Unix # :nodoc:
58
-
59
- # Class representing a parsed path (for UNIX)
60
- class ParsedPath
61
-
62
- # @!visibility private
63
- module ParsedPath_Constants # :nodoc: all
64
-
65
- INIT_VALID_OPTIONS = %i{ home locator pwd }
66
- INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
67
- INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
68
- end
69
-
70
- # Initialises an instance from the given +path+, optional
71
- # +search_directory+ and options
72
- #
73
- # === Signature
74
- #
75
- # * *Parameters:*
76
- # - +path+ (String) The path. May not be +nil+
77
- # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
78
- # - +options+ (Hash) Options
79
- #
80
- # * *Options:*
81
- # - +????+
82
- #
83
- # * *Exceptions:*
84
- # - +ArgumentError+ Raised if +path+ is +nil+
85
- def initialize path, search_directory = nil, **options
86
-
87
- raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
88
-
89
- _Diagnostics = ::LibPath::Diagnostics
90
- _Internal_Form = ::LibPath::Internal_::Unix::Form
91
- _Util = ::LibPath::Util::Unix
92
- _C = ::LibPath::Path::Unix::ParsedPath::ParsedPath_Constants
93
-
94
- _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
95
-
96
-
97
- abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
98
-
99
- _, _, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, _ = _Internal_Form.split_path(abs_path)
100
-
101
- @given_path = path
102
- @absolute_path = abs_path
103
- @compare_path = _Util.make_compare_path abs_path
104
- @directory = f2_dir
105
- @directory_path = f2_dir
106
- @directory_parts = f6_dir_parts
107
-
108
- @file_full_name = f3_basename
109
- @file_name_only = f4_stem
110
- @file_extension = f5_ext
111
-
112
- if search_directory
113
-
114
- drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
115
-
116
- search_directory = _Util.make_path_absolute(search_directory, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
117
- search_directory = _Internal_Form.append_trailing_slash search_directory
118
-
119
- @search_directory = search_directory
120
- @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
121
- @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
122
- @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, f2_dir, **drp_options)
123
- @search_relative_directory_parts = @search_relative_directory_path.split('/').map { |v| v + '/' }
124
- end
125
- end
126
-
127
- # (String) The path given to initialise the instance
128
- attr_reader :given_path
129
- # (String) The full-path of the instance
130
- attr_reader :absolute_path
131
- # (String) A normalised form of #path that can be used in comparisons
132
- attr_reader :compare_path
133
- # (String) The entry's directory (excluding the #drive if on Windows)
134
- attr_reader :directory
135
- # (String) The full path of the entry's directory
136
- attr_reader :directory_path
137
- alias_method :dirname, :directory_path
138
- # ([String]) An array of directory parts, where each part ends in the path name separator
139
- attr_reader :directory_parts
140
- # (String) The entry's file name (combination of #stem + #extension)
141
- attr_reader :file_full_name
142
- alias_method :basename, :file_full_name
143
- # (String) The entry's file stem
144
- attr_reader :file_name_only
145
- alias_method :stem, :file_name_only
146
- # (String) The entry's file extension
147
- attr_reader :file_extension
148
- alias_method :extension, :file_extension
149
- # (String) The search directory if specified; +nil+ otherwise
150
- attr_reader :search_directory
151
- # (String) The #path relative to #search_directory; +nil+ if no search directory specified
152
- attr_reader :search_relative_path
153
- # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
154
- attr_reader :search_relative_directory_path
155
- # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
156
- attr_reader :search_relative_directory_parts
157
-
158
- # (String) String form of path
159
- def to_s
160
-
161
- absolute_path
162
- end
163
- end
164
-
165
- end # module Unix
55
+
56
+ module LibPath
57
+ module Path
58
+
59
+ module Unix
60
+
61
+ # Class representing a parsed path (for UNIX)
62
+ class ParsedPath
63
+
64
+ # @!visibility private
65
+ module ParsedPath_Constants # :nodoc: all
66
+
67
+ INIT_VALID_OPTIONS = %i{ home locator pwd }
68
+ INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
69
+ INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
70
+ end
71
+
72
+ # Initialises an instance from the given +path+, optional
73
+ # +search_directory+ and options
74
+ #
75
+ # === Signature
76
+ #
77
+ # * *Parameters:*
78
+ # - +path+ (String) The path. May not be +nil+
79
+ # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
80
+ # - +options+ (Hash) Options
81
+ #
82
+ # * *Options:*
83
+ # - +????+
84
+ #
85
+ # * *Exceptions:*
86
+ # - +ArgumentError+ Raised if +path+ is +nil+
87
+ def initialize path, search_directory = nil, **options
88
+
89
+ raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
90
+
91
+ _Diagnostics = ::LibPath::Diagnostics
92
+ _Internal_Form = ::LibPath::Internal_::Unix::Form
93
+ _Util = ::LibPath::Util::Unix
94
+ _C = ::LibPath::Path::Unix::ParsedPath::ParsedPath_Constants
95
+
96
+ _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
97
+
98
+
99
+ abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
100
+
101
+ _, _, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, _ = _Internal_Form.split_path(abs_path)
102
+
103
+ @given_path = path
104
+ @absolute_path = abs_path
105
+ @compare_path = _Util.make_compare_path abs_path
106
+ @directory = f2_dir
107
+ @directory_path = f2_dir
108
+ @directory_parts = f6_dir_parts
109
+
110
+ @file_full_name = f3_basename
111
+ @file_name_only = f4_stem
112
+ @file_extension = f5_ext
113
+
114
+ if search_directory
115
+
116
+ drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
117
+
118
+ search_directory = _Util.make_path_absolute(search_directory, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
119
+ search_directory = _Internal_Form.append_trailing_slash search_directory
120
+
121
+ @search_directory = search_directory
122
+ @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
123
+ @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
124
+ @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, f2_dir, **drp_options)
125
+ @search_relative_directory_parts = @search_relative_directory_path.split('/').map { |v| v + '/' }
126
+ end
127
+ end
128
+
129
+ # (String) The path given to initialise the instance
130
+ attr_reader :given_path
131
+ # (String) The full-path of the instance
132
+ attr_reader :absolute_path
133
+ # (String) A normalised form of #path that can be used in comparisons
134
+ attr_reader :compare_path
135
+ # (String) The entry's directory (excluding the #drive if on Windows)
136
+ attr_reader :directory
137
+ # (String) The full path of the entry's directory
138
+ attr_reader :directory_path
139
+ alias_method :dirname, :directory_path
140
+ # ([String]) An array of directory parts, where each part ends in the path name separator
141
+ attr_reader :directory_parts
142
+ # (String) The entry's file name (combination of #stem + #extension)
143
+ attr_reader :file_full_name
144
+ alias_method :basename, :file_full_name
145
+ # (String) The entry's file stem
146
+ attr_reader :file_name_only
147
+ alias_method :stem, :file_name_only
148
+ # (String) The entry's file extension
149
+ attr_reader :file_extension
150
+ alias_method :extension, :file_extension
151
+ # (String) The search directory if specified; +nil+ otherwise
152
+ attr_reader :search_directory
153
+ # (String) The #path relative to #search_directory; +nil+ if no search directory specified
154
+ attr_reader :search_relative_path
155
+ # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
156
+ attr_reader :search_relative_directory_path
157
+ # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
158
+ attr_reader :search_relative_directory_parts
159
+
160
+ # (String) String form of path
161
+ def to_s
162
+
163
+ absolute_path
164
+ end
165
+ end
166
+ end # module Unix
166
167
  end # module Path
167
168
  end # module LibPath
168
169
 
170
+
169
171
  # ############################## end of file ############################# #
170
172
 
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: libpath/path/windows.rb
3
+ # File: libpath/path/windows.rb
4
4
  #
5
- # Purpose: LibPath::Path::Windows module
5
+ # Purpose: LibPath::Path::Windows module
6
6
  #
7
- # Created: 21st January 2019
8
- # Updated: 16th April 2019
7
+ # Created: 21st January 2019
8
+ # Updated: 7th April 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/libpath.Ruby
10
+ # Home: http://github.com/synesissoftware/libpath.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -44,7 +45,6 @@
44
45
  # ######################################################################## #
45
46
 
46
47
 
47
-
48
48
  =begin
49
49
  =end
50
50
 
@@ -52,125 +52,127 @@ require 'libpath/diagnostics'
52
52
  require 'libpath/internal_/windows/form'
53
53
  require 'libpath/util/windows'
54
54
 
55
- module LibPath # :nodoc:
56
- module Path # :nodoc:
57
- module Windows # :nodoc:
58
-
59
- # Class representing a parsed path (for Windows)
60
- class ParsedPath
61
-
62
- # @!visibility private
63
- module ParsedPath_Constants # :nodoc: all
64
-
65
- INIT_VALID_OPTIONS = %i{ home locator pwd }
66
- INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
67
- INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
68
- end
69
-
70
- # Initialises an instance from the given +path+, optional
71
- # +search_directory+ and options
72
- #
73
- # === Signature
74
- #
75
- # * *Parameters:*
76
- # - +path+ (String) The path. May not be +nil+
77
- # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
78
- # - +options+ (Hash) Options
79
- #
80
- # * *Options:*
81
- # - +????+
82
- #
83
- # * *Exceptions:*
84
- # - +ArgumentError+ Raised if +path+ is +nil+
85
- def initialize path, search_directory = nil, **options
86
-
87
- raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
88
-
89
- _Diagnostics = ::LibPath::Diagnostics
90
- _Internal_Form = ::LibPath::Internal_::Windows::Form
91
- _Util = ::LibPath::Util::Windows
92
- _C = ::LibPath::Path::Windows::ParsedPath::ParsedPath_Constants
93
-
94
- _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
95
-
96
-
97
- abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
98
-
99
- splits = _Internal_Form.split_path(abs_path)
100
-
101
- _, f1_vol, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, f7_abs_parts = *splits
102
-
103
- @given_path = path
104
- @absolute_path = abs_path
105
- @compare_path = _Util.make_compare_path abs_path, splits: splits
106
- @volume = f1_vol
107
- @directory = f2_dir
108
- @directory_path = "#{f1_vol}#{f2_dir}"
109
- @directory_parts = f6_dir_parts
110
-
111
- @file_full_name = f3_basename
112
- @file_name_only = f4_stem
113
- @file_extension = f5_ext
114
-
115
- if search_directory
116
-
117
- drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
118
-
119
- search_directory = _Util.make_path_canonical search_directory, make_slashes_canonical: true
120
- search_directory = _Internal_Form.append_trailing_slash search_directory
121
-
122
- @search_directory = search_directory
123
- @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
124
- @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
125
- @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, "#{f1_vol}#{f2_dir}", **drp_options)
126
- @search_relative_directory_parts = @search_relative_directory_path.split('\\').map { |v| v + '\\' }
127
- end
128
- end
129
-
130
- # (String) The path given to initialise the instance
131
- attr_reader :given_path
132
- # (String) The full-path of the instance
133
- attr_reader :absolute_path
134
- # (String) A normalised form of #path that can be used in comparisons
135
- attr_reader :compare_path
136
- # (String) The Windows volume, which may be a drive, or a UNC specification
137
- attr_reader :volume
138
- # (String) The entry's directory (excluding the #drive if on Windows)
139
- attr_reader :directory
140
- # (String) The full path of the entry's directory (taking into account the
141
- # #drive if on Windows)
142
- attr_reader :directory_path
143
- alias_method :dirname, :directory_path
144
- # ([String]) An array of directory parts, where each part ends in the path name separator
145
- attr_reader :directory_parts
146
- # (String) The entry's file name (combination of #stem + #extension)
147
- attr_reader :file_full_name
148
- alias_method :basename, :file_full_name
149
- # (String) The entry's file stem
150
- attr_reader :file_name_only
151
- alias_method :stem, :file_name_only
152
- # (String) The entry's file extension
153
- attr_reader :file_extension
154
- alias_method :extension, :file_extension
155
- # (String) The search directory if specified; +nil+ otherwise
156
- attr_reader :search_directory
157
- # (String) The #path relative to #search_directory; +nil+ if no search directory specified
158
- attr_reader :search_relative_path
159
- # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
160
- attr_reader :search_relative_directory_path
161
- # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
162
- attr_reader :search_relative_directory_parts
163
-
164
- # (String) String form of path
165
- def to_s
166
-
167
- absolute_path
168
- end
169
- end
170
-
171
- end # module Windows
55
+
56
+ module LibPath
57
+ module Path
58
+
59
+ module Windows
60
+
61
+ # Class representing a parsed path (for Windows)
62
+ class ParsedPath
63
+
64
+ # @!visibility private
65
+ module ParsedPath_Constants # :nodoc: all
66
+
67
+ INIT_VALID_OPTIONS = %i{ home locator pwd }
68
+ INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
69
+ INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
70
+ end
71
+
72
+ # Initialises an instance from the given +path+, optional
73
+ # +search_directory+ and options
74
+ #
75
+ # === Signature
76
+ #
77
+ # * *Parameters:*
78
+ # - +path+ (String) The path. May not be +nil+
79
+ # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
80
+ # - +options+ (Hash) Options
81
+ #
82
+ # * *Options:*
83
+ # - +????+
84
+ #
85
+ # * *Exceptions:*
86
+ # - +ArgumentError+ Raised if +path+ is +nil+
87
+ def initialize path, search_directory = nil, **options
88
+
89
+ raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
90
+
91
+ _Diagnostics = ::LibPath::Diagnostics
92
+ _Internal_Form = ::LibPath::Internal_::Windows::Form
93
+ _Util = ::LibPath::Util::Windows
94
+ _C = ::LibPath::Path::Windows::ParsedPath::ParsedPath_Constants
95
+
96
+ _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
97
+
98
+
99
+ abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
100
+
101
+ splits = _Internal_Form.split_path(abs_path)
102
+
103
+ _, f1_vol, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, f7_abs_parts = *splits
104
+
105
+ @given_path = path
106
+ @absolute_path = abs_path
107
+ @compare_path = _Util.make_compare_path abs_path, splits: splits
108
+ @volume = f1_vol
109
+ @directory = f2_dir
110
+ @directory_path = "#{f1_vol}#{f2_dir}"
111
+ @directory_parts = f6_dir_parts
112
+
113
+ @file_full_name = f3_basename
114
+ @file_name_only = f4_stem
115
+ @file_extension = f5_ext
116
+
117
+ if search_directory
118
+
119
+ drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
120
+
121
+ search_directory = _Util.make_path_canonical search_directory, make_slashes_canonical: true
122
+ search_directory = _Internal_Form.append_trailing_slash search_directory
123
+
124
+ @search_directory = search_directory
125
+ @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
126
+ @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
127
+ @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, "#{f1_vol}#{f2_dir}", **drp_options)
128
+ @search_relative_directory_parts = @search_relative_directory_path.split('\\').map { |v| v + '\\' }
129
+ end
130
+ end
131
+
132
+ # (String) The path given to initialise the instance
133
+ attr_reader :given_path
134
+ # (String) The full-path of the instance
135
+ attr_reader :absolute_path
136
+ # (String) A normalised form of #path that can be used in comparisons
137
+ attr_reader :compare_path
138
+ # (String) The Windows volume, which may be a drive, or a UNC specification
139
+ attr_reader :volume
140
+ # (String) The entry's directory (excluding the #drive if on Windows)
141
+ attr_reader :directory
142
+ # (String) The full path of the entry's directory (taking into account the
143
+ # #drive if on Windows)
144
+ attr_reader :directory_path
145
+ alias_method :dirname, :directory_path
146
+ # ([String]) An array of directory parts, where each part ends in the path name separator
147
+ attr_reader :directory_parts
148
+ # (String) The entry's file name (combination of #stem + #extension)
149
+ attr_reader :file_full_name
150
+ alias_method :basename, :file_full_name
151
+ # (String) The entry's file stem
152
+ attr_reader :file_name_only
153
+ alias_method :stem, :file_name_only
154
+ # (String) The entry's file extension
155
+ attr_reader :file_extension
156
+ alias_method :extension, :file_extension
157
+ # (String) The search directory if specified; +nil+ otherwise
158
+ attr_reader :search_directory
159
+ # (String) The #path relative to #search_directory; +nil+ if no search directory specified
160
+ attr_reader :search_relative_path
161
+ # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
162
+ attr_reader :search_relative_directory_path
163
+ # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
164
+ attr_reader :search_relative_directory_parts
165
+
166
+ # (String) String form of path
167
+ def to_s
168
+
169
+ absolute_path
170
+ end
171
+ end
172
+ end # module Windows
172
173
  end # module Path
173
174
  end # module LibPath
174
175
 
176
+
175
177
  # ############################## end of file ############################# #
176
178
 
data/lib/libpath/path.rb CHANGED
@@ -3,41 +3,41 @@ require 'libpath/internal_/platform'
3
3
 
4
4
  if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
5
5
 
6
- require 'libpath/path/windows'
6
+ require 'libpath/path/windows'
7
7
  else
8
8
 
9
- require 'libpath/path/unix'
9
+ require 'libpath/path/unix'
10
10
  end
11
11
 
12
- module LibPath # :nodoc:
13
- module Path # :nodoc:
14
12
 
15
- if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
13
+ module LibPath
14
+ # @!visibility private
15
+ module Path # :nodoc:
16
16
 
17
- extend ::LibPath::Path::Windows
18
- include ::LibPath::Path::Windows
19
- else
17
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
20
18
 
21
- extend ::LibPath::Path::Unix
22
- include ::LibPath::Path::Unix
23
- end
19
+ extend ::LibPath::Path::Windows
20
+ include ::LibPath::Path::Windows
21
+ else
24
22
 
25
- # @!visibility private
26
- def self.extended receiver # :nodoc:
23
+ extend ::LibPath::Path::Unix
24
+ include ::LibPath::Path::Unix
25
+ end
27
26
 
28
- $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
29
- end
27
+ # @!visibility private
28
+ def self.extended receiver # :nodoc:
30
29
 
31
- # @!visibility private
32
- def self.included receiver # :nodoc:
30
+ $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
31
+ end
33
32
 
34
- $stderr.puts "#{receiver} included #{self}" if $DEBUG
35
- end
33
+ # @!visibility private
34
+ def self.included receiver # :nodoc:
36
35
 
36
+ $stderr.puts "#{receiver} included #{self}" if $DEBUG
37
+ end
37
38
  end # module Path
38
39
  end # module LibPath
39
40
 
40
- # ############################## end of file ############################# #
41
-
42
41
 
42
+ # ############################## end of file ############################# #
43
43