cmpfs-ruby 0.2.1.1 → 0.2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62764eb741e0f301f90321e85c93b0dce924c67194106b0bd1303bf6aa546783
4
- data.tar.gz: 5959477f700c9a53c720bb5576a09efaf86cce525e10b5523d043fc72c75918d
3
+ metadata.gz: 2ef217a9a168e19ff15d4884b0910bde940ab5f7ab204ed3037e3521844bf845
4
+ data.tar.gz: 45439f73e36b1c2b27dfd17c67d2bde9c6e6ef35e66c64275204af9118aba2df
5
5
  SHA512:
6
- metadata.gz: 0a07bfafb304a4a1ae80c144ff232b88617c34e6b8392457fd1b7454dbec32be79da00d03f137ec7e2cf089399876fd185a5b0aac31a1fb94131934b60b37498
7
- data.tar.gz: 3e7e33b928703d0c48a2c41d3c765be2dcfd7c77bc8278bea466e9f39e1e76e8e7cd66f6a27083523d547f7d0021c72dee731aa4f0b7658ee7dcf2fa3029d1b5
6
+ metadata.gz: b539e9b6c0650fcacf55a1137e635e6822c28bd952f3a9aaeecb3e666b8225f177ca947f790387bf43dd384f7f8c680d968621a9af7326590cff9e82ee923945
7
+ data.tar.gz: 3368c43940335aa538e856aeda5b8924fb517ef69c59913705fea88765e1714dfa1c5cfc30ce4cd99757f1b01e29454de1bb9995fee717a8ee5cab7468773b90
data/README.md CHANGED
@@ -4,10 +4,12 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/cmpfs-ruby.svg)](https://badge.fury.io/rb/cmpfs-ruby)
6
6
 
7
+
7
8
  ## Introduction
8
9
 
9
10
  Provides platform-independent facilities for comparing file contents, for both binary and text files
10
11
 
12
+
11
13
  ## Table of Contents <!-- omit in toc -->
12
14
 
13
15
  - [Introduction](#introduction)
@@ -21,17 +23,122 @@ Provides platform-independent facilities for comparing file contents, for both b
21
23
  - [Related projects](#related-projects)
22
24
  - [License](#license)
23
25
 
26
+
24
27
  ## Installation
25
28
 
26
29
  Install using `gem install cmpfs-ruby` or add it to your `Gemfile`.
27
30
 
31
+
28
32
  ## Components
29
33
 
30
- T.B.C.
34
+ The primary components provided are the functions:
35
+
36
+ * `CmpFS::Compare.compare_binary_files()`
37
+ * `CmpFS::Compare.compare_binary_streams()`
38
+ * `CmpFS::Compare.compare_binary()`
39
+ * `CmpFS::Compare.compare_text_files()`
40
+ * `CmpFS::Compare.compare_text_streams()`
41
+ * `CmpFS::Compare.compare_text()`
42
+
43
+ all of which are obtained when `extend`ing or `include`ing the `CmpFS` module.
44
+
31
45
 
32
46
  ## Examples
33
47
 
34
- T.B.C.
48
+ **examples/compare_two_binary_files.rb**:
49
+ ```Ruby
50
+ #! /usr/bin/env ruby
51
+
52
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
53
+
54
+
55
+ require 'cmpfs'
56
+
57
+
58
+ include CmpFS
59
+
60
+
61
+ # command-line handling
62
+
63
+ lhs_path, rhs_path =
64
+ case ARGV.size
65
+ when 0, 1
66
+
67
+ if '--help' == ARGV[0]
68
+
69
+ $stdout.puts "#$0: <lhs-path> <rhs-path>"
70
+
71
+ exit 0
72
+ end
73
+
74
+ abort "#$0: not enough arguments; use --help for usage"
75
+ when 2
76
+
77
+ ARGV[0..2]
78
+ else
79
+
80
+ abort "#$0: too many arguments; use --help for usage"
81
+ end
82
+
83
+
84
+ # main()
85
+
86
+
87
+ $stdout.puts "binary comparison of '#{lhs_path}' with '#{rhs_path}':"
88
+
89
+ $stdout.puts "files are #{compare_binary(lhs_path, rhs_path) ? '' : 'not '}equal"
90
+
91
+
92
+ # ############################## end of file ############################# #
93
+ ```
94
+
95
+ **examples/compare_two_text_files.rb**:
96
+ ```Ruby
97
+ #! /usr/bin/env ruby
98
+
99
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
100
+
101
+
102
+ require 'cmpfs'
103
+
104
+
105
+ include CmpFS
106
+
107
+
108
+ # command-line handling
109
+
110
+ lhs_path, rhs_path =
111
+ case ARGV.size
112
+ when 0, 1
113
+
114
+ if '--help' == ARGV[0]
115
+
116
+ $stdout.puts "#$0: <lhs-path> <rhs-path>"
117
+
118
+ exit 0
119
+ end
120
+
121
+ abort "#$0: not enough arguments; use --help for usage"
122
+ when 2
123
+
124
+ ARGV[0..2]
125
+ else
126
+
127
+ abort "#$0: too many arguments; use --help for usage"
128
+ end
129
+
130
+
131
+ # main()
132
+
133
+
134
+ $stdout.puts "text comparison of '#{lhs_path}' with '#{rhs_path}':"
135
+
136
+ $stdout.puts "files are #{compare_text(lhs_path, rhs_path, skip_blank_lines: true, trim_lines: true) ? '' : 'not '}equal"
137
+
138
+
139
+ # ############################## end of file ############################# #
140
+ ```
141
+
35
142
 
36
143
  ## Project Information
37
144
 
@@ -39,16 +146,20 @@ T.B.C.
39
146
 
40
147
  [GitHub Page](https://github.com/synesissoftware/cmpfs.Ruby "GitHub Page")
41
148
 
149
+
42
150
  ### Contribution guidelines
43
151
 
44
152
  Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/cmpfs.Ruby.
45
153
 
154
+
46
155
  ### Dependencies
47
156
 
157
+
48
158
  ### Related projects
49
159
 
50
160
  T.B.C.
51
161
 
162
+
52
163
  ### License
53
164
 
54
165
  **cmpfs.Ruby** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
@@ -0,0 +1,44 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
4
+
5
+
6
+ require 'cmpfs'
7
+
8
+
9
+ include CmpFS
10
+
11
+
12
+ # command-line handling
13
+
14
+ lhs_path, rhs_path =
15
+ case ARGV.size
16
+ when 0, 1
17
+
18
+ if '--help' == ARGV[0]
19
+
20
+ $stdout.puts "#$0: <lhs-path> <rhs-path>"
21
+
22
+ exit 0
23
+ end
24
+
25
+ abort "#$0: not enough arguments; use --help for usage"
26
+ when 2
27
+
28
+ ARGV[0..2]
29
+ else
30
+
31
+ abort "#$0: too many arguments; use --help for usage"
32
+ end
33
+
34
+
35
+ # main()
36
+
37
+
38
+ $stdout.puts "binary comparison of '#{lhs_path}' with '#{rhs_path}':"
39
+
40
+ $stdout.puts "files are #{compare_binary(lhs_path, rhs_path) ? '' : 'not '}equal"
41
+
42
+
43
+ # ############################## end of file ############################# #
44
+
@@ -0,0 +1,44 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
4
+
5
+
6
+ require 'cmpfs'
7
+
8
+
9
+ include CmpFS
10
+
11
+
12
+ # command-line handling
13
+
14
+ lhs_path, rhs_path =
15
+ case ARGV.size
16
+ when 0, 1
17
+
18
+ if '--help' == ARGV[0]
19
+
20
+ $stdout.puts "#$0: <lhs-path> <rhs-path>"
21
+
22
+ exit 0
23
+ end
24
+
25
+ abort "#$0: not enough arguments; use --help for usage"
26
+ when 2
27
+
28
+ ARGV[0..2]
29
+ else
30
+
31
+ abort "#$0: too many arguments; use --help for usage"
32
+ end
33
+
34
+
35
+ # main()
36
+
37
+
38
+ $stdout.puts "text comparison of '#{lhs_path}' with '#{rhs_path}':"
39
+
40
+ $stdout.puts "files are #{compare_text(lhs_path, rhs_path, skip_blank_lines: true, trim_lines: true) ? '' : 'not '}equal"
41
+
42
+
43
+ # ############################## end of file ############################# #
44
+
@@ -15,6 +15,18 @@ module CmpFS_Compare_Methods
15
15
 
16
16
  # Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
17
17
  # (exact) manner
18
+ #
19
+ # === Signature
20
+ #
21
+ # * *Parameters:*
22
+ # - +lhs_path+:: (+String+) The name of a file
23
+ # - +rhs_path+:: (+String+) The name of a file
24
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
25
+ #
26
+ # * *Options:*
27
+ #
28
+ # === Return
29
+ # +true+ if the files have exactly the same content; +false+ otherwise.
18
30
  def compare_binary_files lhs_path, rhs_path, options = {}
19
31
 
20
32
  options ||= {}
@@ -24,6 +36,19 @@ module CmpFS_Compare_Methods
24
36
 
25
37
  # Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
26
38
  # (exact) manner
39
+ #
40
+ # === Signature
41
+ #
42
+ # * *Parameters:*
43
+ # - +lhs_stm+:: (stream) A stream object
44
+ # - +rhs_stm+:: (stream) A stream object
45
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
46
+ #
47
+ # * *Options:*
48
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
49
+ #
50
+ # === Return
51
+ # +true+ if the streams have exactly the same content; +false+ otherwise.
27
52
  def compare_binary_streams lhs_stm, rhs_stm, options = {}
28
53
 
29
54
  options ||= {}
@@ -33,10 +58,17 @@ module CmpFS_Compare_Methods
33
58
 
34
59
  # Compares two files/streams in a binary (exact) manner
35
60
  #
36
- # == Signature
61
+ # === Signature
62
+ #
63
+ # * *Parameters:*
64
+ # - +lhs+:: (+String+, stream) The name of a file, or a stream object
65
+ # - +rhs+:: (+String+, stream) The name of a file, or a stream object
66
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
37
67
  #
38
- # == Return
68
+ # * *Options:*
69
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
39
70
  #
71
+ # === Return
40
72
  # +true+ if the files/streams have exactly the same content; +false+
41
73
  # otherwise.
42
74
  def compare_binary lhs, rhs, options = {}
@@ -48,25 +80,21 @@ module CmpFS_Compare_Methods
48
80
 
49
81
 
50
82
  # Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
51
- # manner according to the given +options+
83
+ # manner according to the given +options+.
52
84
  #
53
85
  # === Signature
54
86
  #
55
87
  # * *Parameters:*
56
- # - +lhs_path+:: (String) The name of a file
57
- # - +rhs_path+:: (String) The name of a file
58
- # - +options+:: (Hash) Options
88
+ # - +lhs_path+:: (+String+) The name of a file
89
+ # - +rhs_path+:: (+String+) The name of a file
90
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
59
91
  #
60
92
  # * *Options:*
61
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
62
- # should be skipped from the comparison
63
- # - +:trim_lines+:: (boolean) Determines whether lines should be
64
- # trimmed of leading and trailing space (including EOL sequence)
93
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
94
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
65
95
  #
66
96
  # === Return
67
- #
68
- # +true+ if the files/streams have exactly the same content; +false+
69
- # otherwise.
97
+ # +true+ if the files/streams have the same content; +false+ otherwise.
70
98
  def compare_text_files lhs_path, rhs_path, options = {}
71
99
 
72
100
  options |= {}
@@ -74,28 +102,23 @@ module CmpFS_Compare_Methods
74
102
  ::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
75
103
  end
76
104
 
77
- # Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
78
- # manner according to the given +options+
105
+ # Compares two streams, +lhs_stm+ and +rhs_stm+, in a textual
106
+ # manner according to the given +options+.
79
107
  #
80
108
  # === Signature
81
109
  #
82
110
  # * *Parameters:*
83
111
  # - +lhs_stm+:: (stream) A stream object
84
112
  # - +rhs_stm+:: (stream) A stream object
85
- # - +options+:: (Hash) Options
113
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
86
114
  #
87
115
  # * *Options:*
88
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
89
- # rewinding the stream before processing
90
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
91
- # should be skipped from the comparison
92
- # - +:trim_lines+:: (boolean) Determines whether lines should be
93
- # trimmed of leading and trailing space (including EOL sequence)
116
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
117
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
118
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
94
119
  #
95
120
  # === Return
96
- #
97
- # +true+ if the files/streams have exactly the same content; +false+
98
- # otherwise.
121
+ # +true+ if the files/streams have the same content; +false+ otherwise.
99
122
  def compare_text_streams lhs_stm, rhs_stm, options = {}
100
123
 
101
124
  options ||= {}
@@ -103,28 +126,23 @@ module CmpFS_Compare_Methods
103
126
  ::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
104
127
  end
105
128
 
106
- # Compares two files/streams, named by +lhs+ and +rhs+, in a textual
107
- # manner according to the given +options+
129
+ # Compares two files/streams, +lhs+ and +rhs+, in a textual
130
+ # manner according to the given +options+.
108
131
  #
109
132
  # === Signature
110
133
  #
111
134
  # * *Parameters:*
112
- # - +lhs+:: (String, stream) The name of a file, or a stream object
113
- # - +rhs+:: (String, stream) The name of a file, or a stream object
114
- # - +options+:: (Hash) Options
135
+ # - +lhs+:: (+String+, stream) The name of a file, or a stream object
136
+ # - +rhs+:: (+String+, stream) The name of a file, or a stream object
137
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
115
138
  #
116
139
  # * *Options:*
117
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
118
- # rewinding the stream before processing
119
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
120
- # should be skipped from the comparison
121
- # - +:trim_lines+:: (boolean) Determines whether lines should be
122
- # trimmed of leading and trailing space (including EOL sequence)
140
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
141
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
142
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
123
143
  #
124
144
  # === Return
125
- #
126
- # +true+ if the files/streams have exactly the same content; +false+
127
- # otherwise.
145
+ # +true+ if the files/streams have the same content; +false+ otherwise.
128
146
  def compare_text lhs, rhs, options = {}
129
147
 
130
148
  options ||= {}
@@ -15,6 +15,18 @@ module CmpFS_Compare_Methods
15
15
 
16
16
  # Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
17
17
  # (exact) manner
18
+ #
19
+ # === Signature
20
+ #
21
+ # * *Parameters:*
22
+ # - +lhs_path+:: (+String+) The name of a file
23
+ # - +rhs_path+:: (+String+) The name of a file
24
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
25
+ #
26
+ # * *Options:*
27
+ #
28
+ # === Return
29
+ # +true+ if the files have exactly the same content; +false+ otherwise.
18
30
  def compare_binary_files lhs_path, rhs_path, **options
19
31
 
20
32
  ::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
@@ -22,6 +34,19 @@ module CmpFS_Compare_Methods
22
34
 
23
35
  # Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
24
36
  # (exact) manner
37
+ #
38
+ # === Signature
39
+ #
40
+ # * *Parameters:*
41
+ # - +lhs_stm+:: (stream) A stream object
42
+ # - +rhs_stm+:: (stream) A stream object
43
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
44
+ #
45
+ # * *Options:*
46
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
47
+ #
48
+ # === Return
49
+ # +true+ if the streams have exactly the same content; +false+ otherwise.
25
50
  def compare_binary_streams lhs_stm, rhs_stm, **options
26
51
 
27
52
  ::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
@@ -29,10 +54,17 @@ module CmpFS_Compare_Methods
29
54
 
30
55
  # Compares two files/streams in a binary (exact) manner
31
56
  #
32
- # == Signature
57
+ # === Signature
58
+ #
59
+ # * *Parameters:*
60
+ # - +lhs+:: (+String+, stream) The name of a file, or a stream object
61
+ # - +rhs+:: (+String+, stream) The name of a file, or a stream object
62
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
33
63
  #
34
- # == Return
64
+ # * *Options:*
65
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
35
66
  #
67
+ # === Return
36
68
  # +true+ if the files/streams have exactly the same content; +false+
37
69
  # otherwise.
38
70
  def compare_binary lhs, rhs, **options
@@ -42,79 +74,65 @@ module CmpFS_Compare_Methods
42
74
 
43
75
 
44
76
  # Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
45
- # manner according to the given +options+
77
+ # manner according to the given +options+.
46
78
  #
47
79
  # === Signature
48
80
  #
49
81
  # * *Parameters:*
50
- # - +lhs_path+:: (String) The name of a file
51
- # - +rhs_path+:: (String) The name of a file
52
- # - +options+:: (Hash) Options
82
+ # - +lhs_path+:: (+String+) The name of a file
83
+ # - +rhs_path+:: (+String+) The name of a file
84
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
53
85
  #
54
86
  # * *Options:*
55
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
56
- # should be skipped from the comparison
57
- # - +:trim_lines+:: (boolean) Determines whether lines should be
58
- # trimmed of leading and trailing space (including EOL sequence)
87
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
88
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
59
89
  #
60
90
  # === Return
61
- #
62
- # +true+ if the files/streams have exactly the same content; +false+
63
- # otherwise.
91
+ # +true+ if the files/streams have the same content; +false+ otherwise.
64
92
  def compare_text_files lhs_path, rhs_path, **options
65
93
 
66
94
  ::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
67
95
  end
68
96
 
69
- # Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
70
- # manner according to the given +options+
97
+ # Compares two streams, +lhs_stm+ and +rhs_stm+, in a textual
98
+ # manner according to the given +options+.
71
99
  #
72
100
  # === Signature
73
101
  #
74
102
  # * *Parameters:*
75
103
  # - +lhs_stm+:: (stream) A stream object
76
104
  # - +rhs_stm+:: (stream) A stream object
77
- # - +options+:: (Hash) Options
105
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
78
106
  #
79
107
  # * *Options:*
80
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
81
- # rewinding the stream before processing
82
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
83
- # should be skipped from the comparison
84
- # - +:trim_lines+:: (boolean) Determines whether lines should be
85
- # trimmed of leading and trailing space (including EOL sequence)
108
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
109
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
110
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
86
111
  #
87
112
  # === Return
88
- #
89
- # +true+ if the files/streams have exactly the same content; +false+
90
- # otherwise.
113
+ # +true+ if the files/streams have the same content; +false+ otherwise.
91
114
  def compare_text_streams lhs_stm, rhs_stm, **options
92
115
 
93
116
  ::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
94
117
  end
95
118
 
96
- # Compares two files/streams, named by +lhs+ and +rhs+, in a textual
97
- # manner according to the given +options+
119
+ # Compares two files/streams, +lhs+ and +rhs+, in a textual
120
+ # manner according to the given +options+.
98
121
  #
99
122
  # === Signature
100
123
  #
101
124
  # * *Parameters:*
102
- # - +lhs+:: (String, stream) The name of a file, or a stream object
103
- # - +rhs+:: (String, stream) The name of a file, or a stream object
104
- # - +options+:: (Hash) Options
125
+ # - +lhs+:: (+String+, stream) The name of a file, or a stream object
126
+ # - +rhs+:: (+String+, stream) The name of a file, or a stream object
127
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
105
128
  #
106
129
  # * *Options:*
107
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
108
- # rewinding the stream before processing
109
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
110
- # should be skipped from the comparison
111
- # - +:trim_lines+:: (boolean) Determines whether lines should be
112
- # trimmed of leading and trailing space (including EOL sequence)
130
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
131
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
132
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
113
133
  #
114
134
  # === Return
115
- #
116
- # +true+ if the files/streams have exactly the same content; +false+
117
- # otherwise.
135
+ # +true+ if the files/streams have the same content; +false+ otherwise.
118
136
  def compare_text lhs, rhs, **options
119
137
 
120
138
  ::CmpFS::Compare::Text::Internal_.compare_text_ lhs, rhs, options
@@ -38,8 +38,8 @@ module Internal_
38
38
 
39
39
  def self.compare_binary_ lhs, rhs, options
40
40
 
41
- lhs_type = self.determine_param_type_ lhs
42
- rhs_type = self.determine_param_type_ rhs
41
+ lhs_type = self.determine_param_type_ lhs
42
+ rhs_type = self.determine_param_type_ rhs
43
43
 
44
44
  raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
45
45
  raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
@@ -61,19 +61,19 @@ module Internal_
61
61
 
62
62
  if :path == rhs_type
63
63
 
64
- File.open(rhs, 'rb') do |rhs_f|
64
+ File.open(rhs, 'rb') do |rhs_f|
65
65
 
66
- return self.compare_binary_streams_ lhs, rhs_f, options
67
- end
66
+ return self.compare_binary_streams_ lhs, rhs_f, options
67
+ end
68
68
  end
69
69
  when :path
70
70
 
71
71
  if :path == lhs_type
72
72
 
73
- File.open(lhs, 'rb') do |lhs_f|
73
+ File.open(lhs, 'rb') do |lhs_f|
74
74
 
75
- return self.compare_binary_streams_ lhs_f, rhs, options
76
- end
75
+ return self.compare_binary_streams_ lhs_f, rhs, options
76
+ end
77
77
  end
78
78
  end
79
79
  end
@@ -28,10 +28,10 @@ module Internal_
28
28
 
29
29
  def self.next_line_or_nil_ en, options
30
30
 
31
- skipping_blanks = options[:skip_blank_lines]
32
- trimming_lines = options[:trim_lines]
31
+ skipping_blanks = options[:skip_blank_lines]
32
+ trimming_lines = options[:trim_lines]
33
33
 
34
- num_read = 0
34
+ num_read = 0
35
35
 
36
36
  begin
37
37
 
@@ -45,7 +45,7 @@ module Internal_
45
45
 
46
46
  if line.empty? && skipping_blanks
47
47
 
48
- next
48
+ next
49
49
  end
50
50
 
51
51
  return [ line, num_read ]
@@ -70,8 +70,8 @@ module Internal_
70
70
 
71
71
  def self.compare_text_streams_ lhs_stm, rhs_stm, options
72
72
 
73
- lhs_en = lhs_stm.each_line
74
- rhs_en = rhs_stm.each_line
73
+ lhs_en = lhs_stm.each_line
74
+ rhs_en = rhs_stm.each_line
75
75
 
76
76
  unless options[:no_rewind]
77
77
 
@@ -79,13 +79,13 @@ module Internal_
79
79
  rhs_en.rewind if rhs_stm.respond_to?(:rewind)
80
80
  end
81
81
 
82
- lhs_ix = 0
83
- rhs_ix = 0
82
+ lhs_ix = 0
83
+ rhs_ix = 0
84
84
 
85
85
  loop do
86
86
 
87
- lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
88
- rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
87
+ lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
88
+ rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
89
89
 
90
90
  if lhs_ln != rhs_ln
91
91
 
@@ -101,8 +101,8 @@ module Internal_
101
101
 
102
102
  def self.compare_text_ lhs, rhs, options
103
103
 
104
- lhs_type = self.determine_param_type_ lhs
105
- rhs_type = self.determine_param_type_ rhs
104
+ lhs_type = self.determine_param_type_ lhs
105
+ rhs_type = self.determine_param_type_ rhs
106
106
 
107
107
  raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
108
108
  raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
@@ -124,19 +124,19 @@ module Internal_
124
124
 
125
125
  if :path == rhs_type
126
126
 
127
- File.open(rhs, 'r') do |rhs_f|
127
+ File.open(rhs, 'r') do |rhs_f|
128
128
 
129
- return self.compare_text_streams_ lhs, rhs_f, options
130
- end
129
+ return self.compare_text_streams_ lhs, rhs_f, options
130
+ end
131
131
  end
132
132
  when :path
133
133
 
134
134
  if :path == lhs_type
135
135
 
136
- File.open(lhs, 'r') do |lhs_f|
136
+ File.open(lhs, 'r') do |lhs_f|
137
137
 
138
- return self.compare_text_streams_ lhs_f, rhs, options
139
- end
138
+ return self.compare_text_streams_ lhs_f, rhs, options
139
+ end
140
140
  end
141
141
  end
142
142
  end
data/lib/cmpfs/compare.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for cmpfs.Ruby library
6
6
  #
7
7
  # Created: 1st March 2019
8
- # Updated: 1st April 2024
8
+ # Updated: 2nd April 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/cmpfs.Ruby
11
11
  #
@@ -45,12 +45,12 @@
45
45
  # ######################################################################## #
46
46
 
47
47
 
48
- if RUBY_VERSION >= '2'
48
+ if RUBY_VERSION < '2'
49
49
 
50
- require 'cmpfs/compare/api_2'
50
+ require 'cmpfs/compare/api_1_9'
51
51
  else
52
52
 
53
- require 'cmpfs/compare/api_1_9'
53
+ require 'cmpfs/compare/api_2'
54
54
  end
55
55
 
56
56
 
data/lib/cmpfs/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for cmpfs.Ruby library
6
6
  #
7
7
  # Created: 1st March 2019
8
- # Updated: 1st April 2024
8
+ # Updated: 2nd April 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/cmpfs.Ruby
11
11
  #
@@ -51,7 +51,7 @@
51
51
  module CmpFS
52
52
 
53
53
  # Current version of the cmpfs.Ruby library
54
- VERSION = '0.2.1.1'
54
+ VERSION = '0.2.1.3'
55
55
 
56
56
  private
57
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
data/lib/cmpfs.rb CHANGED
@@ -1,15 +1,15 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: cmpfs.rb
3
+ # File: cmpfs.rb
4
4
  #
5
- # Purpose: Primary require for cmpfs.Ruby library
5
+ # Purpose: Primary require for cmpfs.Ruby library
6
6
  #
7
- # Created: 1st March 2019
8
- # Updated: 13th March 2019
7
+ # Created: 1st March 2019
8
+ # Updated: 2nd April 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/cmpfs.Ruby
10
+ # Home: http://github.com/synesissoftware/cmpfs.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
14
  # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
15
15
  # Copyright (c) 2019, Matthew Wilson and Synesis Software
@@ -15,12 +15,12 @@ class Test_CmpFS_Compare_compare_binary < Test::Unit::TestCase
15
15
 
16
16
  def test__compare_binary__identical_1
17
17
 
18
- lhs = StringIO.new 'abcdefghijiklmno'
19
- rhs_eq = StringIO.new 'abcdefghijiklmno'
18
+ lhs = StringIO.new 'abcdefghijiklmno'
19
+ rhs_eq = StringIO.new 'abcdefghijiklmno'
20
20
 
21
21
  assert CmpFS::Compare.compare_binary(lhs, rhs_eq), 'streams should be the same'
22
22
 
23
- rhs_ne = StringIO.new 'abcdefghijiklmn'
23
+ rhs_ne = StringIO.new 'abcdefghijiklmn'
24
24
 
25
25
  assert_false CmpFS::Compare.compare_binary(lhs, rhs_ne), 'streams should not be the same'
26
26
  end
@@ -36,11 +36,11 @@ class Test_CmpFS_Compare_compare_binary < Test::Unit::TestCase
36
36
  lhs_f.rewind
37
37
  lhs_f.close
38
38
 
39
- rhs_eq = StringIO.new 'abcdefghijiklmno'
39
+ rhs_eq = StringIO.new 'abcdefghijiklmno'
40
40
 
41
41
  assert CmpFS::Compare.compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
42
42
 
43
- rhs_ne = StringIO.new 'abcdefghijiklmnop'
43
+ rhs_ne = StringIO.new 'abcdefghijiklmnop'
44
44
 
45
45
  assert_false CmpFS::Compare.compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
46
46
  ensure
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # executes all other tests
4
4
 
5
- this_dir = File.expand_path(File.dirname(__FILE__))
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
6
 
7
7
  # all tc_*rb in current directory
8
8
  Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
@@ -17,12 +17,12 @@ class Test_CmpFS_compare_binary < Test::Unit::TestCase
17
17
 
18
18
  def test__compare_binary__identical_1
19
19
 
20
- lhs = StringIO.new 'abcdefghijiklmno'
21
- rhs_eq = StringIO.new 'abcdefghijiklmno'
20
+ lhs = StringIO.new 'abcdefghijiklmno'
21
+ rhs_eq = StringIO.new 'abcdefghijiklmno'
22
22
 
23
23
  assert compare_binary(lhs, rhs_eq), 'streams should be the same'
24
24
 
25
- rhs_ne = StringIO.new 'abcdefghijiklmn'
25
+ rhs_ne = StringIO.new 'abcdefghijiklmn'
26
26
 
27
27
  assert_false compare_binary(lhs, rhs_ne), 'streams should not be the same'
28
28
  end
@@ -38,11 +38,11 @@ class Test_CmpFS_compare_binary < Test::Unit::TestCase
38
38
  lhs_f.rewind
39
39
  lhs_f.close
40
40
 
41
- rhs_eq = StringIO.new 'abcdefghijiklmno'
41
+ rhs_eq = StringIO.new 'abcdefghijiklmno'
42
42
 
43
43
  assert compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
44
44
 
45
- rhs_ne = StringIO.new 'abcdefghijiklmnop'
45
+ rhs_ne = StringIO.new 'abcdefghijiklmnop'
46
46
 
47
47
  assert_false compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
48
48
  ensure
@@ -17,19 +17,19 @@ class Test_CmpFS_compare_text < Test::Unit::TestCase
17
17
 
18
18
  def test__compare_text__empty
19
19
 
20
- lhs = StringIO.new
21
- rhs_eq = StringIO.new
20
+ lhs = StringIO.new
21
+ rhs_eq = StringIO.new
22
22
 
23
23
  assert compare_text(lhs, rhs_eq), 'streams should be the same'
24
24
  end
25
25
 
26
26
  def test__compare_text__blank_lines
27
27
 
28
- lhs = StringIO.new <<END_OF_INPUT
28
+ lhs = StringIO.new <<END_OF_INPUT
29
29
 
30
30
 
31
31
  END_OF_INPUT
32
- rhs_eq = StringIO.new <<END_OF_INPUT
32
+ rhs_eq = StringIO.new <<END_OF_INPUT
33
33
 
34
34
 
35
35
  END_OF_INPUT
@@ -39,12 +39,12 @@ END_OF_INPUT
39
39
 
40
40
  def test__compare_text__identical_lines_1
41
41
 
42
- lhs = StringIO.new <<END_OF_INPUT
42
+ lhs = StringIO.new <<END_OF_INPUT
43
43
  line-1
44
44
  line-2
45
45
 
46
46
  END_OF_INPUT
47
- rhs_eq = StringIO.new <<END_OF_INPUT
47
+ rhs_eq = StringIO.new <<END_OF_INPUT
48
48
  line-1
49
49
  line-2
50
50
 
@@ -55,12 +55,12 @@ END_OF_INPUT
55
55
 
56
56
  def test__compare_text__different_lines_1
57
57
 
58
- lhs = StringIO.new <<END_OF_INPUT
58
+ lhs = StringIO.new <<END_OF_INPUT
59
59
  line-1
60
60
  line-2
61
61
 
62
62
  END_OF_INPUT
63
- rhs_ne = StringIO.new <<END_OF_INPUT
63
+ rhs_ne = StringIO.new <<END_OF_INPUT
64
64
  line-1
65
65
  line2
66
66
 
@@ -71,12 +71,12 @@ END_OF_INPUT
71
71
 
72
72
  def test__compare_text__different_lines_2
73
73
 
74
- lhs = StringIO.new <<END_OF_INPUT
74
+ lhs = StringIO.new <<END_OF_INPUT
75
75
  line-1
76
76
 
77
77
  line-2
78
78
  END_OF_INPUT
79
- rhs_ne = StringIO.new <<END_OF_INPUT
79
+ rhs_ne = StringIO.new <<END_OF_INPUT
80
80
  line-1
81
81
  line-2
82
82
 
@@ -87,12 +87,12 @@ END_OF_INPUT
87
87
 
88
88
  def test__compare_text__different_streams_with_permutations_of_trim_and_skip_1
89
89
 
90
- lhs = StringIO.new <<END_OF_INPUT
90
+ lhs = StringIO.new <<END_OF_INPUT
91
91
  line-1
92
92
 
93
93
  line-2
94
94
  END_OF_INPUT
95
- rhs_eq = StringIO.new <<END_OF_INPUT
95
+ rhs_eq = StringIO.new <<END_OF_INPUT
96
96
  line-1
97
97
  line-2
98
98
  END_OF_INPUT
@@ -102,7 +102,7 @@ END_OF_INPUT
102
102
  assert_false compare_text(lhs, rhs_eq, trim_lines: true, skip_blank_lines: false), 'streams should not be the same'
103
103
  assert compare_text(lhs, rhs_eq, trim_lines: true, skip_blank_lines: true), 'streams should be the same'
104
104
 
105
- rhs_ne = StringIO.new <<END_OF_INPUT
105
+ rhs_ne = StringIO.new <<END_OF_INPUT
106
106
  line-1
107
107
  line2
108
108
  END_OF_INPUT
data/test/unit/ts_all.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # executes all other tests
4
4
 
5
- this_dir = File.expand_path(File.dirname(__FILE__))
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
6
 
7
7
  # all tc_*rb in current directory
8
8
  Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmpfs-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.1
4
+ version: 0.2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-02 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xqsr3
@@ -41,6 +41,8 @@ extra_rdoc_files: []
41
41
  files:
42
42
  - LICENSE
43
43
  - README.md
44
+ - examples/compare_two_binary_files.rb
45
+ - examples/compare_two_text_files.rb
44
46
  - lib/cmpfs.rb
45
47
  - lib/cmpfs/compare.rb
46
48
  - lib/cmpfs/compare/api_1_9.rb