Class: MatrizDSL

Inherits:
MatrizAbstracta show all
Defined in:
lib/modai_prct12/matrizDSL.rb

Overview

Clase de Matriz DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operacion) ⇒ MatrizDSL

Inicialización



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/modai_prct12/matrizDSL.rb', line 5

def initialize(operacion)

               @op_texto = operacion.to_s
               
  # Por defecto la operación será & para devolver error
  case @op_texto 

  when "suma"
    @op = "+"   
  when "resta"
    @op = "-"
  when "producto"
    @op = "*"
  else
    @op = "&"   
  end  
        
               @matA = nil
               @matB = nil

end

Instance Attribute Details

#matrizAObject (readonly)

Returns the value of attribute matrizA.



27
28
29
# File 'lib/modai_prct12/matrizDSL.rb', line 27

def matrizA
  @matrizA
end

#matrizBObject (readonly)

Returns the value of attribute matrizB.



27
28
29
# File 'lib/modai_prct12/matrizDSL.rb', line 27

def matrizB
  @matrizB
end

Instance Method Details

#executeObject

Definimos la función de ejecución de la operación



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/modai_prct12/matrizDSL.rb', line 51

def execute
        
        # Comprobamos la validez de la operación
    if @op = "&"
      puts "La Operacion no es valida"
      return 0
    end
        
    # Mostramos las matrices
        if @matA != nil and @matB != nil

      @matrizA = "Matriz" + @claseMat.to_s + ".new(@matA)"
                puts "Matriz A: #{@matA}"

                @matrizB = "Matriz" + @claseMat.to_s + ".new(@matB)"
                puts "Matriz B: #{@matB}"                

                resultado = @matrizA.to_s + "." + @op.to_s + "("  + " " + @matrizB.to_s + ")"
      puts "Resultado de la operacion ( " + @op_texto.to_s + " ): "                        
      resultado = eval(resultado)
#                        puts "Resultado de la operacion ( " + @op_texto.to_s + " ): #{resultado}"

        end
        
end

#operand(other) ⇒ Object

Definimos el operando



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/modai_prct12/matrizDSL.rb', line 37

def operand(other)
        
          
        if(@matA == nil)
                @matA = other
        else
                @matB = other
        end
                     
        execute
        
end

#option(opc) ⇒ Object

Asignamos la opción de matriz



30
31
32
33
34
# File 'lib/modai_prct12/matrizDSL.rb', line 30

def option(opc)
        
    @claseMat = opc
        
end