class Matrixeval::Context::FindByCommandOptions

Attributes

options[R]

Public Class Methods

call(options) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 5
def call(options)
  new(options).call
end
new(options) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 12
def initialize(options)
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 16
def call
  context = Context.all.find do |context|
    context.main_variant == main_variant &&
      context.rest_variants == rest_variants
  end

  raise Error.new("Can't find a corresponding matrix") if context.nil?

  context
end

Private Instance Methods

dig_variant(vector) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 41
def dig_variant(vector)
  if option_key?(vector.key)
    find_variant(vector)
  else
    vector.default_variant
  end
end
find_variant(vector) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 49
def find_variant(vector)
  vector.variants.find do |variant|
    option(vector.key) == variant.key
  end
end
main_variant() click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 29
def main_variant
  dig_variant Config.main_vector
end
option(key) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 55
def option(key)
  options[key.to_sym] || options[key.to_s]
end
option_key?(key) click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 59
def option_key?(key)
  options.key?(key.to_sym) || options.key?(key.to_s)
end
rest_variants() click to toggle source
# File lib/matrixeval/context/find_by_command_options.rb, line 33
def rest_variants
  Config.rest_vectors.map do |vector|
    dig_variant vector
  end.sort do |v1, v2|
    v1.id <=> v2.id
  end
end