ocg 1.4.0 → 1.4.3

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: 0fa3d1a73808ebe1197e76243c66e4d00b0220c4bbe398e2fcf11e1f58c0f243
4
- data.tar.gz: 8709140dacba810330d6ec2b4889002e0a432a1acd4e5af3767ed3a91cded7a4
3
+ metadata.gz: 45e7d61cdd0972c7916e79ea804cfed5c6cdf03abc8748a250026d21f2af3301
4
+ data.tar.gz: 692aff9f1133bc0498ee29a4d14f827cd87d60f0d5a91747a6dc110ec30ad018
5
5
  SHA512:
6
- metadata.gz: 374148f48f17496aa4d6c572c6e091d08f12b79a8bc1172c2605cb91d30bc1e9a70bda8591fc28e96b1445895c17c930f9dff0b96e5c0460a98d3ed67a9e8b3a
7
- data.tar.gz: 1f403b651a77e2b905543008ba198ddbf6ac6eb02dac413de5aab076458d2386815b6c6baf42b77025790273d108e0ba3b13649c7a56ea49e2940dd6245f9a04
6
+ metadata.gz: 7543c7ae5777f111d5bd962437c5febffc0b23ea3310063be99a1319ab6523e23a67f7e58222fc4e694905d0e027eb9edd88784545ab7e2bab0e783d56a3c3f6
7
+ data.tar.gz: 30a95c0daf0cb9794a7827f16f3f701b589e01b4841d6a95cdacea0de208a362c8792a7c80c37a727808ea6acfe7b14449ad33a6b00a49990edd0a73b7e94252
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Option combination generator
2
2
 
3
- | AppVeyor | Circle | Github Actions | Codecov | Gem |
4
- | :------: | :----: | :------------: | :-----: | :-: |
5
- | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ocg?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ocg/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ocg/tree/master) | [![Github Actions test status](https://github.com/andrew-aladev/ocg/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ocg/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ocg/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ocg) | [![Gem](https://img.shields.io/gem/v/ocg.svg)](https://rubygems.org/gems/ocg) |
3
+ | AppVeyor | Jenkins | Github Actions | Codecov | Gem |
4
+ | :------: | :-----: | :------------: | :-----: | :-: |
5
+ | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ocg?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [![Jenkins test status](http://37.187.122.190:58182/buildStatus/icon?job=ocg)](http://37.187.122.190:58182/job/ocg) | [![Github Actions test status](https://github.com/andrew-aladev/ocg/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ocg/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ocg/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ocg) | [![Gem](https://img.shields.io/gem/v/ocg.svg)](https://rubygems.org/gems/ocg) |
6
6
 
7
7
  ## Installation
8
8
 
9
- Operating systems: GNU/Linux, OSX, FreeBSD, Windows.
9
+ Operating systems: GNU/Linux, OSX, FreeBSD.
10
10
 
11
11
  ```sh
12
12
  gem install ocg
@@ -50,6 +50,8 @@ It will populate all option combinations.
50
50
 
51
51
  ## Docs
52
52
 
53
+ Please review [rdoc generated docs](https://andrew-aladev.github.io/ocg).
54
+
53
55
  `OCG.new options` will prepare a generator.
54
56
  It will provide all possible option combinations.
55
57
 
data/lib/ocg/copyable.rb CHANGED
@@ -2,9 +2,11 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
+ # OCG::Copyable module.
5
6
  module Copyable
6
7
  VARIABLES_TO_COPY = [].freeze
7
8
 
9
+ # Initializes copy of +source+ object using +VARIABLES_TO_COPY+ keys.
8
10
  def initialize_copy(source)
9
11
  self.class::VARIABLES_TO_COPY.each do |variable|
10
12
  key = "@#{variable}".to_sym
data/lib/ocg/main.rb CHANGED
@@ -7,38 +7,53 @@ require_relative "copyable"
7
7
  require_relative "error"
8
8
  require_relative "options"
9
9
 
10
+ # OCG class.
10
11
  class OCG
11
12
  include Copyable
12
13
  include ::Enumerable
13
14
  extend ::Forwardable
14
15
 
15
- DELEGATORS = %i[reset next last started? finished? length].freeze
16
+ # Current delegators.
17
+ DELEGATORS = %i[reset next last started? finished? length].freeze
18
+
19
+ # Current variables to copy.
16
20
  VARIABLES_TO_COPY = %i[generator].freeze
17
21
 
22
+ # Define current delegators.
18
23
  def_delegators :@generator, *DELEGATORS
19
24
 
25
+ # Initializes options generator using +generator_or_options+.
26
+ # +generator_or_options+ may be +generator+ object or +options+.
27
+ # +options+ is a hash with values convertable to array.
20
28
  def initialize(generator_or_options = {})
21
29
  @generator = self.class.prepare_generator generator_or_options
22
30
  end
23
31
 
32
+ # Prepares options generator using +generator_or_options+.
33
+ # +generator_or_options+ may be +generator+ object or +options+.
34
+ # +options+ is a hash with values convertable to array.
24
35
  def self.prepare_generator(generator_or_options)
25
36
  return generator_or_options if generator_or_options.is_a? OCG
26
37
 
27
38
  Options.new generator_or_options
28
39
  end
29
40
 
41
+ # Adds +generator_or_options+ to current option combinations generator.
30
42
  def and(generator_or_options = {})
31
43
  Operator::AND.new self, generator_or_options
32
44
  end
33
45
 
46
+ # Mixes +generator_or_options+ with current option combinations generator.
34
47
  def mix(generator_or_options = {})
35
48
  Operator::MIX.new self, generator_or_options
36
49
  end
37
50
 
51
+ # Mixes +generator_or_options+ with current option combinations generator.
38
52
  def or(generator_or_options = {})
39
53
  Operator::OR.new self, generator_or_options
40
54
  end
41
55
 
56
+ # Processes each option combination.
42
57
  def each(&_block)
43
58
  instance = dup
44
59
  instance.reset
@@ -5,9 +5,12 @@ require_relative "../error"
5
5
 
6
6
  class OCG
7
7
  module Operator
8
+ # OCG::Operator::Abstract class.
8
9
  class Abstract < OCG
9
10
  VARIABLES_TO_COPY = %i[left_generator right_generator].freeze
10
11
 
12
+ # Initializes operator using +left_generator_or_options+ and +right_generator_or_options+.
13
+ # Internaly object initializes left and right generators.
11
14
  def initialize(left_generator_or_options, right_generator_or_options) # rubocop:disable Lint/MissingSuper
12
15
  @left_generator = OCG.prepare_generator left_generator_or_options
13
16
  @right_generator = OCG.prepare_generator right_generator_or_options
@@ -15,6 +18,7 @@ class OCG
15
18
  reset
16
19
  end
17
20
 
21
+ # Resets left and right generators specifically for options.
18
22
  def reset
19
23
  @left_generator.reset
20
24
  @right_generator.reset
@@ -22,6 +26,7 @@ class OCG
22
26
  nil
23
27
  end
24
28
 
29
+ # Merges results specifically for options.
25
30
  protected def merge_results(left, right)
26
31
  if left.nil?
27
32
  right
@@ -5,7 +5,9 @@ require_relative "abstract"
5
5
 
6
6
  class OCG
7
7
  module Operator
8
+ # OCG::Operator::AND class.
8
9
  class AND < Abstract
10
+ # Get next option combination result.
9
11
  def next
10
12
  return nil if finished?
11
13
 
@@ -22,6 +24,7 @@ class OCG
22
24
  merge_results left, right
23
25
  end
24
26
 
27
+ # Get last option combination result.
25
28
  def last
26
29
  left = @left_generator.last
27
30
  right = @right_generator.last
@@ -29,14 +32,17 @@ class OCG
29
32
  merge_results left, right
30
33
  end
31
34
 
32
- def started?
33
- @left_generator.started? || @right_generator.started?
34
- end
35
-
35
+ # Is option combinations generation finished?
36
36
  def finished?
37
37
  @left_generator.finished? && @right_generator.finished?
38
38
  end
39
39
 
40
+ # Is option combinations generation started?
41
+ def started?
42
+ @left_generator.started? || @right_generator.started?
43
+ end
44
+
45
+ # Get options combination length.
40
46
  def length
41
47
  left_length = @left_generator.length
42
48
  right_length = @right_generator.length
@@ -5,19 +5,23 @@ require_relative "abstract"
5
5
 
6
6
  class OCG
7
7
  module Operator
8
+ # OCG::Operator::MIX class.
8
9
  class MIX < Abstract
10
+ # Initializes current generators.
9
11
  def initialize(*args)
10
12
  super
11
13
 
12
14
  reset_main_generator
13
15
  end
14
16
 
17
+ # Initializes copy of current generators.
15
18
  def initialize_copy(*args)
16
19
  super
17
20
 
18
21
  reset_main_generator
19
22
  end
20
23
 
24
+ # Resets left or right generator based on internal state.
21
25
  def reset_main_generator
22
26
  @main_generator =
23
27
  if @right_generator.length > @left_generator.length
@@ -27,6 +31,7 @@ class OCG
27
31
  end
28
32
  end
29
33
 
34
+ # Get next option combination result.
30
35
  def next
31
36
  return nil if finished?
32
37
 
@@ -39,6 +44,7 @@ class OCG
39
44
  merge_results left, right
40
45
  end
41
46
 
47
+ # Get last option combination result.
42
48
  def last
43
49
  left = @left_generator.last
44
50
  right = @right_generator.last
@@ -46,14 +52,17 @@ class OCG
46
52
  merge_results left, right
47
53
  end
48
54
 
49
- def started?
50
- @main_generator.started?
51
- end
52
-
55
+ # Is option combinations generation finished?
53
56
  def finished?
54
57
  @main_generator.finished?
55
58
  end
56
59
 
60
+ # Is option combinations generation started?
61
+ def started?
62
+ @main_generator.started?
63
+ end
64
+
65
+ # Get options combination length.
57
66
  def length
58
67
  @main_generator.length
59
68
  end
@@ -5,7 +5,9 @@ require_relative "abstract"
5
5
 
6
6
  class OCG
7
7
  module Operator
8
+ # OCG::Operator::OR class.
8
9
  class OR < Abstract
10
+ # Get next option combination result.
9
11
  def next
10
12
  return nil if finished?
11
13
 
@@ -16,6 +18,7 @@ class OCG
16
18
  end
17
19
  end
18
20
 
21
+ # Get last option combination result.
19
22
  def last
20
23
  left = @left_generator.last
21
24
  right = @right_generator.last
@@ -27,14 +30,17 @@ class OCG
27
30
  end
28
31
  end
29
32
 
33
+ # Is option combinations generation started?
30
34
  def started?
31
35
  @left_generator.started? || @right_generator.started?
32
36
  end
33
37
 
38
+ # Is option combinations generation finished?
34
39
  def finished?
35
40
  @left_generator.finished? && @right_generator.finished?
36
41
  end
37
42
 
43
+ # Get option combinations length.
38
44
  def length
39
45
  @left_generator.length + @right_generator.length
40
46
  end
data/lib/ocg/options.rb CHANGED
@@ -5,11 +5,15 @@ require_relative "copyable"
5
5
  require_relative "validation"
6
6
 
7
7
  class OCG
8
+ # OCG::Options class.
8
9
  class Options
9
10
  include Copyable
10
11
 
12
+ # Current variables to be copied.
11
13
  VARIABLES_TO_COPY = %i[options keys last_options value_indexes].freeze
12
14
 
15
+ # Initializes options using +options+ values.
16
+ # +options+ is a hash with values convertable to array.
13
17
  def initialize(options)
14
18
  Validation.validate_options options
15
19
  @options = options.transform_values(&:to_a)
@@ -24,10 +28,12 @@ class OCG
24
28
  @is_finished = length.zero?
25
29
  end
26
30
 
31
+ # Resets internal value indexes.
27
32
  protected def reset_value_indexes
28
33
  @value_indexes = @options.transform_values { |_values| 0 }
29
34
  end
30
35
 
36
+ # Resets current option combinations state.
31
37
  def reset
32
38
  return nil unless started?
33
39
 
@@ -41,10 +47,11 @@ class OCG
41
47
  nil
42
48
  end
43
49
 
50
+ # Get next option combination.
44
51
  def next
45
52
  return nil if @is_finished
46
53
 
47
- @last_options = @value_indexes.map { |name, value_index| [name, @options[name][value_index]] }.to_h
54
+ @last_options = @value_indexes.to_h { |name, value_index| [name, @options[name][value_index]] }
48
55
 
49
56
  @is_finished = @keys.all? do |name|
50
57
  values = @options[name]
@@ -63,18 +70,22 @@ class OCG
63
70
  @last_options
64
71
  end
65
72
 
73
+ # Get last option combination.
66
74
  def last
67
75
  @last_options
68
76
  end
69
77
 
78
+ # Is option combinations generation started?
70
79
  def started?
71
80
  !@last_options.nil?
72
81
  end
73
82
 
83
+ # Is option combinations generation finished?
74
84
  def finished?
75
85
  @is_finished
76
86
  end
77
87
 
88
+ # Get option combinations length.
78
89
  def length
79
90
  @options.reduce(0) do |length, (_name, values)|
80
91
  if length.zero?
@@ -4,7 +4,11 @@
4
4
  require_relative "error"
5
5
 
6
6
  class OCG
7
+ # OCG::Validation module.
7
8
  module Validation
9
+ # Raises error when +options+ is not hash
10
+ # and option values are not convertable to array
11
+ # and option values are not empty.
8
12
  def self.validate_options(options)
9
13
  raise ValidateError, "invalid options hash" unless options.is_a? ::Hash
10
14
 
data/lib/ocg/version.rb CHANGED
@@ -2,5 +2,6 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
- VERSION = "1.4.0".freeze
5
+ # Option combination generator version.
6
+ VERSION = "1.4.3".freeze
6
7
  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.4.0
4
+ version: 1.4.3
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-30 00:00:00.000000000 Z
11
+ date: 2022-06-30 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.16'
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.16'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,48 +66,62 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.22'
89
+ version: '1.31'
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: '1.22'
96
+ version: '1.31'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-minitest
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.15'
103
+ version: '0.20'
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: '0.15'
110
+ version: '0.20'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop-performance
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '1.11'
117
+ version: '1.14'
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: '1.11'
124
+ version: '1.14'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rubocop-rake
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +173,8 @@ files:
159
173
  homepage: https://github.com/andrew-aladev/ocg
160
174
  licenses:
161
175
  - MIT
162
- metadata: {}
176
+ metadata:
177
+ rubygems_mfa_required: 'true'
163
178
  post_install_message:
164
179
  rdoc_options: []
165
180
  require_paths:
@@ -168,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
183
  requirements:
169
184
  - - ">="
170
185
  - !ruby/object:Gem::Version
171
- version: '2.5'
186
+ version: '2.6'
172
187
  required_rubygems_version: !ruby/object:Gem::Requirement
173
188
  requirements:
174
189
  - - ">="
175
190
  - !ruby/object:Gem::Version
176
191
  version: '0'
177
192
  requirements: []
178
- rubygems_version: 3.2.22
193
+ rubygems_version: 3.3.7
179
194
  signing_key:
180
195
  specification_version: 4
181
196
  summary: Option combination generator.