class Lopata::ScenarioBuilder::Option

@private

Attributes

key[R]
use_all_variants[R]
variants[R]

Public Class Methods

new(key, variants, use_all_variants = true) click to toggle source
# File lib/lopata/scenario_builder.rb, line 452
def initialize(key, variants, use_all_variants = true)
  @key = key
  @variants =
    if variants.is_a? Hash
      variants.map { |title, value| Variant.new(self, key, title, value) }
    else
      # Array of arrays of two elements
      variants.map { |v| Variant.new(self, key, *v) }
    end
  @use_all_variants = use_all_variants
end

Public Instance Methods

available_metadata_keys() click to toggle source
# File lib/lopata/scenario_builder.rb, line 481
def available_metadata_keys
  @available_metadata_keys ||= variants
    .map(&:value).select { |v| v.is_a?(Hash) }.flat_map(&:keys).map { |k| "#{key}_#{k}".to_sym  }.uniq
end
level_variants() click to toggle source

Variants to apply at one level

# File lib/lopata/scenario_builder.rb, line 465
def level_variants
  variants
end
next_variant() click to toggle source
# File lib/lopata/scenario_builder.rb, line 469
def next_variant
  @current ||= 0
  selected_variant = variants[@current]
  @current += 1
  @complete = true unless use_all_variants # not need to verify all variants, just use first ones.
  if @current >= variants.length
    @current = 0
    @complete = true # all variants have been selected
  end
  selected_variant
end