libpath-ruby 0.2.2 → 0.2.2.1

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 +71 -71
  7. data/lib/libpath/constants/windows.rb +72 -72
  8. data/lib/libpath/constants.rb +18 -19
  9. data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +104 -103
  15. data/lib/libpath/form/windows.rb +200 -199
  16. data/lib/libpath/form.rb +18 -18
  17. data/lib/libpath/internal_/array.rb +53 -53
  18. data/lib/libpath/internal_/platform.rb +24 -24
  19. data/lib/libpath/internal_/string.rb +18 -18
  20. data/lib/libpath/internal_/unix/form.rb +116 -116
  21. data/lib/libpath/internal_/windows/drive.rb +59 -59
  22. data/lib/libpath/internal_/windows/form.rb +189 -189
  23. data/lib/libpath/libpath.rb +3 -0
  24. data/lib/libpath/path/unix.rb +114 -112
  25. data/lib/libpath/path/windows.rb +120 -118
  26. data/lib/libpath/path.rb +18 -20
  27. data/lib/libpath/util/unix.rb +258 -258
  28. data/lib/libpath/util/windows.rb +400 -400
  29. data/lib/libpath/util.rb +18 -19
  30. data/lib/libpath/version.rb +23 -24
  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: 6th 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
+
55
56
  module LibPath # :nodoc:
56
57
  module Path # :nodoc:
57
58
  module Unix # :nodoc:
58
59
 
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
60
+ # Class representing a parsed path (for UNIX)
61
+ class ParsedPath
62
+
63
+ # @!visibility private
64
+ module ParsedPath_Constants # :nodoc: all
65
+
66
+ INIT_VALID_OPTIONS = %i{ home locator pwd }
67
+ INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
68
+ INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
69
+ end
70
+
71
+ # Initialises an instance from the given +path+, optional
72
+ # +search_directory+ and options
73
+ #
74
+ # === Signature
75
+ #
76
+ # * *Parameters:*
77
+ # - +path+ (String) The path. May not be +nil+
78
+ # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
79
+ # - +options+ (Hash) Options
80
+ #
81
+ # * *Options:*
82
+ # - +????+
83
+ #
84
+ # * *Exceptions:*
85
+ # - +ArgumentError+ Raised if +path+ is +nil+
86
+ def initialize path, search_directory = nil, **options
87
+
88
+ raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
89
+
90
+ _Diagnostics = ::LibPath::Diagnostics
91
+ _Internal_Form = ::LibPath::Internal_::Unix::Form
92
+ _Util = ::LibPath::Util::Unix
93
+ _C = ::LibPath::Path::Unix::ParsedPath::ParsedPath_Constants
94
+
95
+ _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
96
+
97
+
98
+ abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
99
+
100
+ _, _, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, _ = _Internal_Form.split_path(abs_path)
101
+
102
+ @given_path = path
103
+ @absolute_path = abs_path
104
+ @compare_path = _Util.make_compare_path abs_path
105
+ @directory = f2_dir
106
+ @directory_path = f2_dir
107
+ @directory_parts = f6_dir_parts
108
+
109
+ @file_full_name = f3_basename
110
+ @file_name_only = f4_stem
111
+ @file_extension = f5_ext
112
+
113
+ if search_directory
114
+
115
+ drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
116
+
117
+ search_directory = _Util.make_path_absolute(search_directory, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
118
+ search_directory = _Internal_Form.append_trailing_slash search_directory
119
+
120
+ @search_directory = search_directory
121
+ @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
122
+ @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
123
+ @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, f2_dir, **drp_options)
124
+ @search_relative_directory_parts = @search_relative_directory_path.split('/').map { |v| v + '/' }
125
+ end
126
+ end
127
+
128
+ # (String) The path given to initialise the instance
129
+ attr_reader :given_path
130
+ # (String) The full-path of the instance
131
+ attr_reader :absolute_path
132
+ # (String) A normalised form of #path that can be used in comparisons
133
+ attr_reader :compare_path
134
+ # (String) The entry's directory (excluding the #drive if on Windows)
135
+ attr_reader :directory
136
+ # (String) The full path of the entry's directory
137
+ attr_reader :directory_path
138
+ alias_method :dirname, :directory_path
139
+ # ([String]) An array of directory parts, where each part ends in the path name separator
140
+ attr_reader :directory_parts
141
+ # (String) The entry's file name (combination of #stem + #extension)
142
+ attr_reader :file_full_name
143
+ alias_method :basename, :file_full_name
144
+ # (String) The entry's file stem
145
+ attr_reader :file_name_only
146
+ alias_method :stem, :file_name_only
147
+ # (String) The entry's file extension
148
+ attr_reader :file_extension
149
+ alias_method :extension, :file_extension
150
+ # (String) The search directory if specified; +nil+ otherwise
151
+ attr_reader :search_directory
152
+ # (String) The #path relative to #search_directory; +nil+ if no search directory specified
153
+ attr_reader :search_relative_path
154
+ # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
155
+ attr_reader :search_relative_directory_path
156
+ # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
157
+ attr_reader :search_relative_directory_parts
158
+
159
+ # (String) String form of path
160
+ def to_s
161
+
162
+ absolute_path
163
+ end
164
+ end
164
165
 
165
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: 6th 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
+
55
56
  module LibPath # :nodoc:
56
57
  module Path # :nodoc:
57
58
  module Windows # :nodoc:
58
59
 
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
60
+ # Class representing a parsed path (for Windows)
61
+ class ParsedPath
62
+
63
+ # @!visibility private
64
+ module ParsedPath_Constants # :nodoc: all
65
+
66
+ INIT_VALID_OPTIONS = %i{ home locator pwd }
67
+ INIT_MPA_COMMON_OPTIONS = %i{ home locator pwd }
68
+ INIT_DRP_COMMON_OPTIONS = %i{ home locator pwd }
69
+ end
70
+
71
+ # Initialises an instance from the given +path+, optional
72
+ # +search_directory+ and options
73
+ #
74
+ # === Signature
75
+ #
76
+ # * *Parameters:*
77
+ # - +path+ (String) The path. May not be +nil+
78
+ # - +search_directory+ (String) The search_directory, from which the relative attributes are calculated for the path. May be +nil+
79
+ # - +options+ (Hash) Options
80
+ #
81
+ # * *Options:*
82
+ # - +????+
83
+ #
84
+ # * *Exceptions:*
85
+ # - +ArgumentError+ Raised if +path+ is +nil+
86
+ def initialize path, search_directory = nil, **options
87
+
88
+ raise ::ArgumentError, "path may not be nil or empty" if path.nil? || path.empty?
89
+
90
+ _Diagnostics = ::LibPath::Diagnostics
91
+ _Internal_Form = ::LibPath::Internal_::Windows::Form
92
+ _Util = ::LibPath::Util::Windows
93
+ _C = ::LibPath::Path::Windows::ParsedPath::ParsedPath_Constants
94
+
95
+ _Diagnostics.check_options(options, known: _C::INIT_VALID_OPTIONS)
96
+
97
+
98
+ abs_path = _Util.make_path_absolute(path, make_canonical: true, **options.select { |k| _C::INIT_MPA_COMMON_OPTIONS.include?(k) })
99
+
100
+ splits = _Internal_Form.split_path(abs_path)
101
+
102
+ _, f1_vol, f2_dir, f3_basename, f4_stem, f5_ext, f6_dir_parts, f7_abs_parts = *splits
103
+
104
+ @given_path = path
105
+ @absolute_path = abs_path
106
+ @compare_path = _Util.make_compare_path abs_path, splits: splits
107
+ @volume = f1_vol
108
+ @directory = f2_dir
109
+ @directory_path = "#{f1_vol}#{f2_dir}"
110
+ @directory_parts = f6_dir_parts
111
+
112
+ @file_full_name = f3_basename
113
+ @file_name_only = f4_stem
114
+ @file_extension = f5_ext
115
+
116
+ if search_directory
117
+
118
+ drp_options = options.select { |k| _C::INIT_DRP_COMMON_OPTIONS.include?(k) }
119
+
120
+ search_directory = _Util.make_path_canonical search_directory, make_slashes_canonical: true
121
+ search_directory = _Internal_Form.append_trailing_slash search_directory
122
+
123
+ @search_directory = search_directory
124
+ @search_relative_path = _Util.derive_relative_path(search_directory, abs_path, **drp_options)
125
+ @search_relative_path = _Internal_Form.append_trailing_slash(@search_relative_path) if _Internal_Form.char_is_path_name_separator?(abs_path[-1])
126
+ @search_relative_directory_path = _Internal_Form.append_trailing_slash _Util.derive_relative_path(search_directory, "#{f1_vol}#{f2_dir}", **drp_options)
127
+ @search_relative_directory_parts = @search_relative_directory_path.split('\\').map { |v| v + '\\' }
128
+ end
129
+ end
130
+
131
+ # (String) The path given to initialise the instance
132
+ attr_reader :given_path
133
+ # (String) The full-path of the instance
134
+ attr_reader :absolute_path
135
+ # (String) A normalised form of #path that can be used in comparisons
136
+ attr_reader :compare_path
137
+ # (String) The Windows volume, which may be a drive, or a UNC specification
138
+ attr_reader :volume
139
+ # (String) The entry's directory (excluding the #drive if on Windows)
140
+ attr_reader :directory
141
+ # (String) The full path of the entry's directory (taking into account the
142
+ # #drive if on Windows)
143
+ attr_reader :directory_path
144
+ alias_method :dirname, :directory_path
145
+ # ([String]) An array of directory parts, where each part ends in the path name separator
146
+ attr_reader :directory_parts
147
+ # (String) The entry's file name (combination of #stem + #extension)
148
+ attr_reader :file_full_name
149
+ alias_method :basename, :file_full_name
150
+ # (String) The entry's file stem
151
+ attr_reader :file_name_only
152
+ alias_method :stem, :file_name_only
153
+ # (String) The entry's file extension
154
+ attr_reader :file_extension
155
+ alias_method :extension, :file_extension
156
+ # (String) The search directory if specified; +nil+ otherwise
157
+ attr_reader :search_directory
158
+ # (String) The #path relative to #search_directory; +nil+ if no search directory specified
159
+ attr_reader :search_relative_path
160
+ # (String) The #directory_path relative to #search_directory; +nil+ if no search directory specified
161
+ attr_reader :search_relative_directory_path
162
+ # ([String]) The #directory_parts relative to #search_directory; +nil+ if no search directory specified
163
+ attr_reader :search_relative_directory_parts
164
+
165
+ # (String) String form of path
166
+ def to_s
167
+
168
+ absolute_path
169
+ end
170
+ end
170
171
 
171
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,39 @@ 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
12
  module LibPath # :nodoc:
13
13
  module Path # :nodoc:
14
14
 
15
- if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
15
+ if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
16
16
 
17
- extend ::LibPath::Path::Windows
18
- include ::LibPath::Path::Windows
19
- else
17
+ extend ::LibPath::Path::Windows
18
+ include ::LibPath::Path::Windows
19
+ else
20
20
 
21
- extend ::LibPath::Path::Unix
22
- include ::LibPath::Path::Unix
23
- end
21
+ extend ::LibPath::Path::Unix
22
+ include ::LibPath::Path::Unix
23
+ end
24
24
 
25
- # @!visibility private
26
- def self.extended receiver # :nodoc:
25
+ # @!visibility private
26
+ def self.extended receiver # :nodoc:
27
27
 
28
- $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
29
- end
28
+ $stderr.puts "#{receiver} extended by #{self}" if $DEBUG
29
+ end
30
30
 
31
- # @!visibility private
32
- def self.included receiver # :nodoc:
33
-
34
- $stderr.puts "#{receiver} included #{self}" if $DEBUG
35
- end
31
+ # @!visibility private
32
+ def self.included receiver # :nodoc:
36
33
 
34
+ $stderr.puts "#{receiver} included #{self}" if $DEBUG
35
+ end
37
36
  end # module Path
38
37
  end # module LibPath
39
38
 
40
- # ############################## end of file ############################# #
41
-
42
39
 
40
+ # ############################## end of file ############################# #
43
41