class Dsl

Attributes

modo_resultado[RW]
operacion[RW]
operando[RW]
tipo_matriz[RW]

Public Class Methods

new(operacion) { |self| ... } click to toggle source
# File lib/Dsl.rb, line 8
def initialize (operacion, &block)
  raise ArgumentError , 'Operacion no valida' unless operacion.is_a? String
  
  @operacion = operacion
  @operando = []
  @tipo_matriz = ""
  @modo_resultado = ""
  
  case operacion
  when "suma"
    @operacion = "suma"
  when "resta"
    @operacion = "resta"
  when "multiplicacion"
    @operacion = "multiplicacion"
  end
  
  if block_given?  
    if block.arity == 1
      yield self
    else
      instance_eval &block 
    end
  end
  
  case @modo_resultado
  when "consola"
    puts self
  when "fichero"
    File.open('resultado.txt','a+') do |x|
      x.puts self
    end
    puts self
  end
end

Public Instance Methods

ejecucion() click to toggle source
# File lib/Dsl.rb, line 68
def ejecucion
  mostrar = []
  
  case @operacion
  when "suma"
    mostrar = (@operando[0] + @operando[1]).matriz
  when "resta"
    mostrar = (@operando[0] - @operando[1]).matriz
  when "multiplicacion"
    mostrar = (@operando[0] * @operando[1]).matriz
  end
  
  mostrar
end
option(cadena) click to toggle source
# File lib/Dsl.rb, line 57
def option(cadena)
      raise ArgumentError , 'Opcion no valida' unless cadena.is_a? String
      opcion = cadena.downcase
      case opcion
       when "consola","fichero"  
         @modo = opcion
       when "dispersa","densa" 
         @tipo = opcion
      end
end