Class: Matrixeval::Vector
- Inherits:
-
Object
- Object
- Matrixeval::Vector
- Defined in:
- lib/matrixeval/vector.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#variants ⇒ Object
readonly
Returns the value of attribute variants.
Instance Method Summary collapse
- #default_variant ⇒ Object
- #id ⇒ Object
-
#initialize(key, config) ⇒ Vector
constructor
A new instance of Vector.
- #main? ⇒ Boolean
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/matrixeval/vector.rb', line 3 def key @key end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
3 4 5 |
# File 'lib/matrixeval/vector.rb', line 3 def main @main end |
#variants ⇒ Object (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_variant ⇒ Object
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 |
#id ⇒ Object
25 26 27 |
# File 'lib/matrixeval/vector.rb', line 25 def id "#{key.to_s.gsub(/[^A-Za-z0-9]/,'_')}" end |