Class: OCG

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Copyable
Defined in:
lib/ocg/main.rb,
lib/ocg/error.rb,
lib/ocg/options.rb,
lib/ocg/version.rb,
lib/ocg/copyable.rb,
lib/ocg/validation.rb,
lib/ocg/operator/or.rb,
lib/ocg/operator/and.rb,
lib/ocg/operator/mix.rb,
lib/ocg/operator/abstract.rb

Overview

Option combination generator. Copyright © 2019 AUTHORS, MIT License.

Direct Known Subclasses

Operator::Abstract

Defined Under Namespace

Modules: Copyable, Operator, Validation Classes: BaseError, NotImplementedError, Options, ValidateError

Constant Summary collapse

DELEGATORS =

Current delegators.

%i[reset next last started? finished? length].freeze
VARIABLES_TO_COPY =

Current variables to copy.

%i[generator].freeze
VERSION =

Option combination generator version.

"1.4.3".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Copyable

#initialize_copy

Constructor Details

#initialize(generator_or_options = {}) ⇒ OCG

Initializes options generator using generator_or_options. generator_or_options may be generator object or options. options is a hash with values convertable to array.



28
29
30
# File 'lib/ocg/main.rb', line 28

def initialize(generator_or_options = {})
  @generator = self.class.prepare_generator generator_or_options
end

Class Method Details

.prepare_generator(generator_or_options) ⇒ Object

Prepares options generator using generator_or_options. generator_or_options may be generator object or options. options is a hash with values convertable to array.



35
36
37
38
39
# File 'lib/ocg/main.rb', line 35

def self.prepare_generator(generator_or_options)
  return generator_or_options if generator_or_options.is_a? OCG

  Options.new generator_or_options
end

Instance Method Details

#and(generator_or_options = {}) ⇒ Object

Adds generator_or_options to current option combinations generator.



42
43
44
# File 'lib/ocg/main.rb', line 42

def and(generator_or_options = {})
  Operator::AND.new self, generator_or_options
end

#each(&_block) ⇒ Object

Processes each option combination.



57
58
59
60
61
62
63
64
# File 'lib/ocg/main.rb', line 57

def each(&_block)
  instance = dup
  instance.reset

  yield instance.next until instance.finished?

  nil
end

#mix(generator_or_options = {}) ⇒ Object

Mixes generator_or_options with current option combinations generator.



47
48
49
# File 'lib/ocg/main.rb', line 47

def mix(generator_or_options = {})
  Operator::MIX.new self, generator_or_options
end

#or(generator_or_options = {}) ⇒ Object

Mixes generator_or_options with current option combinations generator.



52
53
54
# File 'lib/ocg/main.rb', line 52

def or(generator_or_options = {})
  Operator::OR.new self, generator_or_options
end