ocg 1.3.4 → 1.4.2

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: 2c061519b8e290df24b149da93956abfafc1376a873a9b035481a78478619aa6
4
- data.tar.gz: c8c32a9bc9011616c618c8f4bf8adae21e90931ac1061fefa09c5db23879535f
3
+ metadata.gz: 5203959948fc9159061ecbc0218e4f5bf2024d73d448db2d24f345f26143a17c
4
+ data.tar.gz: 71c6d13b14b86e219a464b18f7c83d7095ace6bbdfe5f1a2aa49687e352f67fe
5
5
  SHA512:
6
- metadata.gz: aa1359a517003142c14bbf01fc65a09583eb1f7fbe8feca02c5c318ce3ff625f9701d118fdaee261c88fb5bdff3fa2a4f83de9e258df447cd126736e1abe2692
7
- data.tar.gz: 86a7fc958ba29efb13a8048c0b5fc221b5dc24b553dc8a21462b7bed93a13ace4da8a4d0faeb03492b070a897e42143e42c082c0a1e6d0d8ec7eddaff49796a3
6
+ metadata.gz: 49674ba90890c919316d77d6cab1acf213df64acad0793e754d863b9390d99c66da6f3e49e313db83b136372161d496ebcf46cb0ae30392be2d86305982f3fad
7
+ data.tar.gz: 8ec4f446b6b875c5a34dded0d61a5a043ae2568775efc0fb08380bc5035f8e6b7e760d72d60e6590d94010928f573bd4e6bffccb08ff9b5b9c24d0e24fcbd269
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.4".freeze
5
+ VERSION = "1.4.2".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.4
4
+ version: 1.4.2
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-09-24 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.14'
47
+ version: '5.15'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.14'
54
+ version: '5.15'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.21'
75
+ version: '1.26'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.21'
82
+ version: '1.26'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.15'
89
+ version: '0.17'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.15'
96
+ version: '0.17'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop-performance
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.11'
103
+ version: '1.13'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.11'
110
+ version: '1.13'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,8 @@ files:
159
159
  homepage: https://github.com/andrew-aladev/ocg
160
160
  licenses:
161
161
  - MIT
162
- metadata: {}
162
+ metadata:
163
+ rubygems_mfa_required: 'true'
163
164
  post_install_message:
164
165
  rdoc_options: []
165
166
  require_paths:
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  - !ruby/object:Gem::Version
176
177
  version: '0'
177
178
  requirements: []
178
- rubygems_version: 3.2.22
179
+ rubygems_version: 3.3.7
179
180
  signing_key:
180
181
  specification_version: 4
181
182
  summary: Option combination generator.