cmpfs-ruby 0.2.0 → 0.2.1.2

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.
@@ -1,127 +1,149 @@
1
1
 
2
2
  unless RUBY_VERSION >= '2'
3
3
 
4
- abort "This file required Ruby 2+: RUBY_VERSION='#{RUBY_VERSION}'"
4
+ abort "This file required Ruby 2+: RUBY_VERSION='#{RUBY_VERSION}'"
5
5
  end
6
6
 
7
7
  require 'cmpfs/compare/binary/internal_'
8
8
  require 'cmpfs/compare/text/internal_'
9
9
 
10
+
10
11
  module CmpFS
11
12
  module Compare
12
13
 
13
14
  module CmpFS_Compare_Methods
14
15
 
15
- # Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
16
- # (exact) manner
17
- def compare_binary_files lhs_path, rhs_path, **options
18
-
19
- ::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
20
- end
21
-
22
- # Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
23
- # (exact) manner
24
- def compare_binary_streams lhs_stm, rhs_stm, **options
25
-
26
- ::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
27
- end
28
-
29
- # Compares two files/streams in a binary (exact) manner
30
- #
31
- # == Signature
32
- #
33
- # == Return
34
- #
35
- # +true+ if the files/streams have exactly the same content; +false+
36
- # otherwise.
37
- def compare_binary lhs, rhs, **options
38
-
39
- ::CmpFS::Compare::Binary::Internal_.compare_binary_ lhs, rhs, options
40
- end
41
-
42
-
43
- # Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
44
- # manner according to the given +options+
45
- #
46
- # === Signature
47
- #
48
- # * *Parameters:*
49
- # - +lhs_path+:: (String) The name of a file
50
- # - +rhs_path+:: (String) The name of a file
51
- # - +options+:: (Hash) Options
52
- #
53
- # * *Options:*
54
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
55
- # should be skipped from the comparison
56
- # - +:trim_lines+:: (boolean) Determines whether lines should be
57
- # trimmed of leading and trailing space (including EOL sequence)
58
- #
59
- # === Return
60
- #
61
- # +true+ if the files/streams have exactly the same content; +false+
62
- # otherwise.
63
- def compare_text_files lhs_path, rhs_path, **options
64
-
65
- ::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
66
- end
67
-
68
- # Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
69
- # manner according to the given +options+
70
- #
71
- # === Signature
72
- #
73
- # * *Parameters:*
74
- # - +lhs_stm+:: (stream) A stream object
75
- # - +rhs_stm+:: (stream) A stream object
76
- # - +options+:: (Hash) Options
77
- #
78
- # * *Options:*
79
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
80
- # rewinding the stream before processing
81
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
82
- # should be skipped from the comparison
83
- # - +:trim_lines+:: (boolean) Determines whether lines should be
84
- # trimmed of leading and trailing space (including EOL sequence)
85
- #
86
- # === Return
87
- #
88
- # +true+ if the files/streams have exactly the same content; +false+
89
- # otherwise.
90
- def compare_text_streams lhs_stm, rhs_stm, **options
91
-
92
- ::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
93
- end
94
-
95
- # Compares two files/streams, named by +lhs+ and +rhs+, in a textual
96
- # manner according to the given +options+
97
- #
98
- # === Signature
99
- #
100
- # * *Parameters:*
101
- # - +lhs+:: (String, stream) The name of a file, or a stream object
102
- # - +rhs+:: (String, stream) The name of a file, or a stream object
103
- # - +options+:: (Hash) Options
104
- #
105
- # * *Options:*
106
- # - +:no_rewind+:: (boolean) Prevents the default behaviour of
107
- # rewinding the stream before processing
108
- # - +:skip_blank_lines+:: (boolean) Determines whether blank lines
109
- # should be skipped from the comparison
110
- # - +:trim_lines+:: (boolean) Determines whether lines should be
111
- # trimmed of leading and trailing space (including EOL sequence)
112
- #
113
- # === Return
114
- #
115
- # +true+ if the files/streams have exactly the same content; +false+
116
- # otherwise.
117
- def compare_text lhs, rhs, **options
118
-
119
- ::CmpFS::Compare::Text::Internal_.compare_text_ lhs, rhs, options
120
- end
16
+ # Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
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.
30
+ def compare_binary_files lhs_path, rhs_path, **options
31
+
32
+ ::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
33
+ end
34
+
35
+ # Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
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.
50
+ def compare_binary_streams lhs_stm, rhs_stm, **options
51
+
52
+ ::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
53
+ end
54
+
55
+ # Compares two files/streams in a binary (exact) manner
56
+ #
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
63
+ #
64
+ # * *Options:*
65
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
66
+ #
67
+ # === Return
68
+ # +true+ if the files/streams have exactly the same content; +false+
69
+ # otherwise.
70
+ def compare_binary lhs, rhs, **options
71
+
72
+ ::CmpFS::Compare::Binary::Internal_.compare_binary_ lhs, rhs, options
73
+ end
74
+
75
+
76
+ # Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
77
+ # manner according to the given +options+
78
+ #
79
+ # === Signature
80
+ #
81
+ # * *Parameters:*
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
85
+ #
86
+ # * *Options:*
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)
89
+ #
90
+ # === Return
91
+ # +true+ if the files/streams have exactly the same content; +false+
92
+ # otherwise.
93
+ def compare_text_files lhs_path, rhs_path, **options
94
+
95
+ ::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
96
+ end
97
+
98
+ # Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
99
+ # manner according to the given +options+
100
+ #
101
+ # === Signature
102
+ #
103
+ # * *Parameters:*
104
+ # - +lhs_stm+:: (stream) A stream object
105
+ # - +rhs_stm+:: (stream) A stream object
106
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
107
+ #
108
+ # * *Options:*
109
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
110
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
111
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
112
+ #
113
+ # === Return
114
+ # +true+ if the files/streams have exactly the same content; +false+
115
+ # otherwise.
116
+ def compare_text_streams lhs_stm, rhs_stm, **options
117
+
118
+ ::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
119
+ end
120
+
121
+ # Compares two files/streams, named by +lhs+ and +rhs+, in a textual
122
+ # manner according to the given +options+
123
+ #
124
+ # === Signature
125
+ #
126
+ # * *Parameters:*
127
+ # - +lhs+:: (+String+, stream) The name of a file, or a stream object
128
+ # - +rhs+:: (+String+, stream) The name of a file, or a stream object
129
+ # - +options+:: (+Hash+) Options that control the behaviour of the method
130
+ #
131
+ # * *Options:*
132
+ # - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
133
+ # - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
134
+ # - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
135
+ #
136
+ # === Return
137
+ # +true+ if the files/streams have exactly the same content; +false+
138
+ # otherwise.
139
+ def compare_text lhs, rhs, **options
140
+
141
+ ::CmpFS::Compare::Text::Internal_.compare_text_ lhs, rhs, options
142
+ end
121
143
  end # module CmpFS_Compare_Methods
122
144
  end # module Compare
123
145
  end # module CmpFS
124
146
 
125
- # ############################## end of file ############################# #
126
147
 
148
+ # ############################## end of file ############################# #
127
149
 
@@ -1,89 +1,87 @@
1
1
 
2
- #require 'xqsr3'
3
-
4
2
  require 'fileutils'
5
3
  require 'stringio'
6
4
 
5
+
7
6
  module CmpFS
8
7
  module Compare
9
8
  module Binary
10
9
 
11
10
  module Internal_
12
11
 
13
- def self.determine_param_type_ p
14
-
15
- case p
16
- when ::IO, ::StringIO
12
+ def self.determine_param_type_ p
17
13
 
18
- return :io
19
- when ::String
14
+ case p
15
+ when ::IO, ::StringIO
20
16
 
21
- return :path
22
- else
17
+ return :io
18
+ when ::String
23
19
 
24
- return :path if p.respond_to?(:to_str)
20
+ return :path
21
+ else
25
22
 
26
- return nil
27
- end
28
- end
23
+ return :path if p.respond_to?(:to_str)
29
24
 
30
- def self.compare_binary_files_ lhs_path, rhs_path, options
25
+ return nil
26
+ end
27
+ end
31
28
 
32
- FileUtils.compare_file lhs_path, rhs_path
33
- end
29
+ def self.compare_binary_files_ lhs_path, rhs_path, options
34
30
 
35
- def self.compare_binary_streams_ lhs_stm, rhs_stm, options
31
+ FileUtils.compare_file lhs_path, rhs_path
32
+ end
36
33
 
37
- FileUtils.compare_stream lhs_stm, rhs_stm
38
- end
34
+ def self.compare_binary_streams_ lhs_stm, rhs_stm, options
39
35
 
40
- def self.compare_binary_ lhs, rhs, options
36
+ FileUtils.compare_stream lhs_stm, rhs_stm
37
+ end
41
38
 
39
+ def self.compare_binary_ lhs, rhs, options
42
40
 
43
- lhs_type = self.determine_param_type_ lhs
44
- rhs_type = self.determine_param_type_ rhs
41
+ lhs_type = self.determine_param_type_ lhs
42
+ rhs_type = self.determine_param_type_ rhs
45
43
 
46
- raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
47
- raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
44
+ raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
45
+ raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
48
46
 
49
- if lhs_type == rhs_type
47
+ if lhs_type == rhs_type
50
48
 
51
- case lhs_type
52
- when :io
49
+ case lhs_type
50
+ when :io
53
51
 
54
- return self.compare_binary_streams_ lhs, rhs, options
55
- when :path
52
+ return self.compare_binary_streams_ lhs, rhs, options
53
+ when :path
56
54
 
57
- return self.compare_binary_files_ lhs, rhs, options
58
- end
59
- else
55
+ return self.compare_binary_files_ lhs, rhs, options
56
+ end
57
+ else
60
58
 
61
- case lhs_type
62
- when :io
59
+ case lhs_type
60
+ when :io
63
61
 
64
- if :path == rhs_type
62
+ if :path == rhs_type
65
63
 
66
- File.open(rhs, 'rb') do |rhs_f|
64
+ File.open(rhs, 'rb') do |rhs_f|
67
65
 
68
- return self.compare_binary_streams_ lhs, rhs_f, options
69
- end
70
- end
71
- when :path
66
+ return self.compare_binary_streams_ lhs, rhs_f, options
67
+ end
68
+ end
69
+ when :path
72
70
 
73
- if :path == lhs_type
71
+ if :path == lhs_type
74
72
 
75
- File.open(lhs, 'rb') do |lhs_f|
73
+ File.open(lhs, 'rb') do |lhs_f|
76
74
 
77
- return self.compare_binary_streams_ lhs_f, rhs, options
78
- end
79
- end
80
- end
81
- end
75
+ return self.compare_binary_streams_ lhs_f, rhs, options
76
+ end
77
+ end
78
+ end
79
+ end
82
80
 
83
- warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
81
+ warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
84
82
 
85
- nil
86
- end
83
+ nil
84
+ end
87
85
 
88
86
  end # module Internal_
89
87
 
@@ -91,6 +89,6 @@ end # module Binary
91
89
  end # module Compare
92
90
  end # module CmpFS
93
91
 
94
- # ############################## end of file ############################# #
95
92
 
93
+ # ############################## end of file ############################# #
96
94
 
@@ -1,159 +1,156 @@
1
1
 
2
- #require 'xqsr3'
3
-
4
2
  require 'fileutils'
5
3
  require 'stringio'
6
4
 
5
+
7
6
  module CmpFS
8
7
  module Compare
9
8
  module Text
10
9
 
11
10
  module Internal_
12
11
 
13
- def self.determine_param_type_ p
14
-
15
- case p
16
- when ::IO, ::StringIO
12
+ def self.determine_param_type_ p
17
13
 
18
- return :io
19
- when ::String
14
+ case p
15
+ when ::IO, ::StringIO
20
16
 
21
- return :path
22
- else
17
+ return :io
18
+ when ::String
23
19
 
24
- return :path if p.respond_to?(:to_str)
20
+ return :path
21
+ else
25
22
 
26
- return nil
27
- end
28
- end
23
+ return :path if p.respond_to?(:to_str)
29
24
 
30
- def self.next_line_or_nil_ en, options
25
+ return nil
26
+ end
27
+ end
31
28
 
32
- trimming_lines = options[:trim_lines]
33
- skipping_blanks = options[:skip_blank_lines]
29
+ def self.next_line_or_nil_ en, options
34
30
 
35
- num_read = 0
31
+ skipping_blanks = options[:skip_blank_lines]
32
+ trimming_lines = options[:trim_lines]
36
33
 
37
- begin
34
+ num_read = 0
38
35
 
39
- loop do
36
+ begin
40
37
 
41
- line = en.next
38
+ loop do
42
39
 
43
- num_read += 1
40
+ line = en.next
44
41
 
45
- line = line.strip if trimming_lines
42
+ num_read += 1
46
43
 
47
- if line.empty? && skipping_blanks
44
+ line = line.strip if trimming_lines
48
45
 
49
- next
50
- end
46
+ if line.empty? && skipping_blanks
51
47
 
52
- return [ line, num_read ]
53
- end
54
- rescue StopIteration
48
+ next
49
+ end
55
50
 
56
- end
51
+ return [ line, num_read ]
52
+ end
53
+ rescue StopIteration
57
54
 
58
- return [ nil, num_read ]
59
- end
55
+ end
60
56
 
61
- def self.compare_text_files_ lhs_path, rhs_path, options
57
+ return [ nil, num_read ]
58
+ end
62
59
 
63
- File.open(lhs_path, 'r') do |lhs_stm|
60
+ def self.compare_text_files_ lhs_path, rhs_path, options
64
61
 
65
- File.open(rhs_path, 'r') do |rhs_stm|
62
+ File.open(lhs_path, 'r') do |lhs_stm|
66
63
 
67
- self.compare_text_streams_ lhs_stm, rhs_stm, options.merge(no_rewind: true)
68
- end
69
- end
70
- end
64
+ File.open(rhs_path, 'r') do |rhs_stm|
71
65
 
72
- def self.compare_text_streams_ lhs_stm, rhs_stm, options
66
+ self.compare_text_streams_ lhs_stm, rhs_stm, options.merge(no_rewind: true)
67
+ end
68
+ end
69
+ end
73
70
 
74
- lhs_en = lhs_stm.each_line
75
- rhs_en = rhs_stm.each_line
71
+ def self.compare_text_streams_ lhs_stm, rhs_stm, options
76
72
 
77
- unless options[:no_rewind]
73
+ lhs_en = lhs_stm.each_line
74
+ rhs_en = rhs_stm.each_line
78
75
 
79
- lhs_en.rewind if lhs_stm.respond_to?(:rewind)
80
- rhs_en.rewind if rhs_stm.respond_to?(:rewind)
81
- end
76
+ unless options[:no_rewind]
82
77
 
83
- lhs_ix = 0
84
- rhs_ix = 0
78
+ lhs_en.rewind if lhs_stm.respond_to?(:rewind)
79
+ rhs_en.rewind if rhs_stm.respond_to?(:rewind)
80
+ end
85
81
 
86
- loop do
82
+ lhs_ix = 0
83
+ rhs_ix = 0
87
84
 
88
- lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
89
- rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
85
+ loop do
90
86
 
91
- if lhs_ln != rhs_ln
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
92
89
 
93
- return false
94
- else
90
+ if lhs_ln != rhs_ln
95
91
 
96
- return true if lhs_ln.nil?
97
- end
98
- end
92
+ return false
93
+ else
99
94
 
100
- return true
101
- end
95
+ return true if lhs_ln.nil?
96
+ end
97
+ end
102
98
 
103
- def self.compare_text_ lhs, rhs, options
99
+ return true
100
+ end
104
101
 
105
- lhs_type = self.determine_param_type_ lhs
106
- rhs_type = self.determine_param_type_ rhs
102
+ def self.compare_text_ lhs, rhs, options
107
103
 
108
- raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
109
- raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
104
+ lhs_type = self.determine_param_type_ lhs
105
+ rhs_type = self.determine_param_type_ rhs
110
106
 
111
- if lhs_type == rhs_type
107
+ raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
108
+ raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
112
109
 
113
- case lhs_type
114
- when :io
110
+ if lhs_type == rhs_type
115
111
 
116
- return self.compare_text_streams_ lhs, rhs, options
117
- when :path
112
+ case lhs_type
113
+ when :io
118
114
 
119
- return self.compare_text_files_ lhs, rhs, options
120
- end
121
- else
115
+ return self.compare_text_streams_ lhs, rhs, options
116
+ when :path
122
117
 
123
- case lhs_type
124
- when :io
118
+ return self.compare_text_files_ lhs, rhs, options
119
+ end
120
+ else
125
121
 
126
- if :path == rhs_type
122
+ case lhs_type
123
+ when :io
127
124
 
128
- File.open(rhs, 'r') do |rhs_f|
125
+ if :path == rhs_type
129
126
 
130
- return self.compare_text_streams_ lhs, rhs_f, options
131
- end
132
- end
133
- when :path
127
+ File.open(rhs, 'r') do |rhs_f|
134
128
 
135
- if :path == lhs_type
129
+ return self.compare_text_streams_ lhs, rhs_f, options
130
+ end
131
+ end
132
+ when :path
136
133
 
137
- File.open(lhs, 'r') do |lhs_f|
134
+ if :path == lhs_type
138
135
 
139
- return self.compare_text_streams_ lhs_f, rhs, options
140
- end
141
- end
142
- end
143
- end
136
+ File.open(lhs, 'r') do |lhs_f|
144
137
 
145
- warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
138
+ return self.compare_text_streams_ lhs_f, rhs, options
139
+ end
140
+ end
141
+ end
142
+ end
146
143
 
147
- nil
148
- end
144
+ warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
149
145
 
146
+ nil
147
+ end
150
148
  end # module Internal_
151
149
 
152
150
  end # module Text
153
151
  end # module Compare
154
152
  end # module CmpFS
155
153
 
156
- # ############################## end of file ############################# #
157
-
158
154
 
155
+ # ############################## end of file ############################# #
159
156