ocg 1.3.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1d6d020cfd6918a3911fdbdf27adf4a188e9fe643f43cadb2ff9132b8419d47
4
- data.tar.gz: aa8b3b23e632a29ffdc103c0292e77e91ee79c4e64979c7c0e73e252864ce1ed
3
+ metadata.gz: 50c5eb6bcb6811b447d8e2d3fa1609cf7d0c83194a7566e65ba2392f9196a66c
4
+ data.tar.gz: 29e197326bf5c3f119f36b0a3bed9a380c3fda086ae60d3321409033a08a2a77
5
5
  SHA512:
6
- metadata.gz: 2988e11f4f3576c5cd648832f29256fb6cfc705301954c7b000d61fde7dc343b7f3f99dd6dcc8281191cabf87e8dcc42f7cae3ed1153907f510fdb4ef535450d
7
- data.tar.gz: b1093946df6b54282fcc4c7019c20f453042880068862e0a9fc682033b28b1385b503d1f08f388f44c8119a201ea573f3a54c217b34b1bd89275d8e468981a9e
6
+ metadata.gz: 4874eb2a787efcd8d4b413a24017957c00216847372eb339e1967a9a63648de036a3407c98c161837e7743e451aac777339e60e48f5b3a1d0fa2851f2d41a814
7
+ data.tar.gz: ff01b8071d785bd7c2df2dc4da5bc65baf428e66aad00128e0a19f560700eb710c038a391a4179f08ce38944e714aead12d16974f039d51e88abff68fc832717
data/README.md CHANGED
@@ -82,7 +82,7 @@ Options should be prepared in the following form:
82
82
  }
83
83
  ```
84
84
 
85
- Options hash should not be empty.
85
+ Options hash may be empty.
86
86
  `option_name` can be any valid hash key.
87
87
  `option_values` should be convertable to array using `to_a`.
88
88
  `option_values` should not be empty.
data/lib/ocg/main.rb CHANGED
@@ -17,7 +17,7 @@ class OCG
17
17
 
18
18
  def_delegators :@generator, *DELEGATORS
19
19
 
20
- def initialize(generator_or_options)
20
+ def initialize(generator_or_options = {})
21
21
  @generator = self.class.prepare_generator generator_or_options
22
22
  end
23
23
 
@@ -27,15 +27,15 @@ class OCG
27
27
  Options.new generator_or_options
28
28
  end
29
29
 
30
- def and(generator_or_options)
30
+ def and(generator_or_options = {})
31
31
  Operator::AND.new self, generator_or_options
32
32
  end
33
33
 
34
- def mix(generator_or_options)
34
+ def mix(generator_or_options = {})
35
35
  Operator::MIX.new self, generator_or_options
36
36
  end
37
37
 
38
- def or(generator_or_options)
38
+ def or(generator_or_options = {})
39
39
  Operator::OR.new self, generator_or_options
40
40
  end
41
41
 
@@ -22,6 +22,16 @@ class OCG
22
22
  nil
23
23
  end
24
24
 
25
+ protected def merge_results(left, right)
26
+ if left.nil?
27
+ right
28
+ elsif right.nil?
29
+ left
30
+ else
31
+ left.merge right
32
+ end
33
+ end
34
+
25
35
  # :nocov:
26
36
  def next
27
37
  raise NotImplementedError, "\"next\" is not implemented"
@@ -11,21 +11,22 @@ class OCG
11
11
 
12
12
  if @right_generator.finished?
13
13
  @right_generator.reset
14
- @left_generator.next.merge @right_generator.next
14
+ left = @left_generator.next
15
15
  else
16
- left_last = @left_generator.last
17
- left_last = @left_generator.next if left_last.nil?
18
- left_last.merge @right_generator.next
16
+ left = @left_generator.last
17
+ left = @left_generator.next if left.nil?
19
18
  end
19
+
20
+ right = @right_generator.next
21
+
22
+ merge_results left, right
20
23
  end
21
24
 
22
25
  def last
23
- left_last = @left_generator.last
24
- right_last = @right_generator.last
25
-
26
- return nil if left_last.nil? || right_last.nil?
26
+ left = @left_generator.last
27
+ right = @right_generator.last
27
28
 
28
- left_last.merge right_last
29
+ merge_results left, right
29
30
  end
30
31
 
31
32
  def started?
@@ -37,7 +38,16 @@ class OCG
37
38
  end
38
39
 
39
40
  def length
40
- @left_generator.length * @right_generator.length
41
+ left_length = @left_generator.length
42
+ right_length = @right_generator.length
43
+
44
+ if left_length.zero?
45
+ right_length
46
+ elsif right_length.zero?
47
+ left_length
48
+ else
49
+ left_length * right_length
50
+ end
41
51
  end
42
52
  end
43
53
  end
@@ -32,16 +32,18 @@ class OCG
32
32
 
33
33
  @left_generator.reset if @left_generator.finished?
34
34
  @right_generator.reset if @right_generator.finished?
35
- @left_generator.next.merge @right_generator.next
35
+
36
+ left = @left_generator.next
37
+ right = @right_generator.next
38
+
39
+ merge_results left, right
36
40
  end
37
41
 
38
42
  def last
39
- left_last = @left_generator.last
40
- right_last = @right_generator.last
41
-
42
- return nil if left_last.nil? || right_last.nil?
43
+ left = @left_generator.last
44
+ right = @right_generator.last
43
45
 
44
- left_last.merge right_last
46
+ merge_results left, right
45
47
  end
46
48
 
47
49
  def started?
@@ -17,13 +17,13 @@ class OCG
17
17
  end
18
18
 
19
19
  def last
20
- left_last = @left_generator.last
21
- right_last = @right_generator.last
20
+ left = @left_generator.last
21
+ right = @right_generator.last
22
22
 
23
- if right_last.nil?
24
- left_last
23
+ if right.nil?
24
+ left
25
25
  else
26
- right_last
26
+ right
27
27
  end
28
28
  end
29
29
 
data/lib/ocg/options.rb CHANGED
@@ -21,7 +21,7 @@ class OCG
21
21
 
22
22
  reset_value_indexes
23
23
 
24
- @is_finished = false
24
+ @is_finished = length.zero?
25
25
  end
26
26
 
27
27
  protected def reset_value_indexes
@@ -36,7 +36,7 @@ class OCG
36
36
  # If state is finished than all value indexes are already zero.
37
37
  reset_value_indexes unless @is_finished
38
38
 
39
- @is_finished = false
39
+ @is_finished = length.zero?
40
40
 
41
41
  nil
42
42
  end
@@ -76,7 +76,13 @@ class OCG
76
76
  end
77
77
 
78
78
  def length
79
- @options.reduce(1) { |length, (_name, values)| length * values.length }
79
+ @options.reduce(0) do |length, (_name, values)|
80
+ if length.zero?
81
+ values.length
82
+ else
83
+ length * values.length
84
+ end
85
+ end
80
86
  end
81
87
  end
82
88
  end
@@ -7,7 +7,6 @@ class OCG
7
7
  module Validation
8
8
  def self.validate_options(options)
9
9
  raise ValidateError, "invalid options hash" unless options.is_a? ::Hash
10
- raise ValidateError, "options should not be empty" if options.empty?
11
10
 
12
11
  options.each do |_name, values|
13
12
  raise ValidateError, "option values should respond to \"to_a\"" unless values.respond_to? :to_a
data/lib/ocg/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
- VERSION = "1.3.2".freeze
5
+ VERSION = "1.4.1".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Aladjev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '5.14'
47
+ version: '5.15'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '5.14'
54
+ version: '5.15'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,56 +72,56 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.14'
75
+ version: '1.24'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.14'
82
+ version: '1.24'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop-minitest
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.12'
89
+ version: '0.17'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.12'
96
+ version: '0.17'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-performance
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '1.11'
103
+ version: '1.13'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '1.11'
110
+ version: '1.13'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop-rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0.5'
117
+ version: '0.6'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0.5'
124
+ version: '0.6'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +159,8 @@ files:
145
159
  homepage: https://github.com/andrew-aladev/ocg
146
160
  licenses:
147
161
  - MIT
148
- metadata: {}
162
+ metadata:
163
+ rubygems_mfa_required: 'true'
149
164
  post_install_message:
150
165
  rdoc_options: []
151
166
  require_paths:
@@ -161,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
176
  - !ruby/object:Gem::Version
162
177
  version: '0'
163
178
  requirements: []
164
- rubygems_version: 3.2.15
179
+ rubygems_version: 3.3.3
165
180
  signing_key:
166
181
  specification_version: 4
167
182
  summary: Option combination generator.