Class: Matrixeval::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/matrixeval/vector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, config) ⇒ Vector

Returns a new instance of Vector.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/matrixeval/vector.rb', line 5

def initialize(key, config)
  @key = key.to_s
  @main = !!config["main"]
  @variants = (config["variants"] || []).map do |variant_config|
    _config = if variant_config.is_a?(Hash)
      variant_config
    else
      { "key" => variant_config.to_s }
    end

    Variant.new(_config, self)
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/matrixeval/vector.rb', line 3

def key
  @key
end

#mainObject (readonly)

Returns the value of attribute main.



3
4
5
# File 'lib/matrixeval/vector.rb', line 3

def main
  @main
end

#variantsObject (readonly)

Returns the value of attribute variants.



3
4
5
# File 'lib/matrixeval/vector.rb', line 3

def variants
  @variants
end

Instance Method Details

#default_variantObject



29
30
31
32
33
34
35
36
# File 'lib/matrixeval/vector.rb', line 29

def default_variant
  variant = variants.find(&:default?)
  if variant.nil?
    raise Error.new("Please set a default variant for matrix #{key}")
  end

  variant
end

#idObject



25
26
27
# File 'lib/matrixeval/vector.rb', line 25

def id
  "#{key.to_s.gsub(/[^A-Za-z0-9]/,'_')}"
end

#main?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/matrixeval/vector.rb', line 19

def main?
  return main if Config.target.vector_key.nil?

  Config.target.vector_key == key
end