Class: Cocot

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

Overview

Clase principal de la aplicación.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCocot

Returns a new instance of Cocot.



8
9
10
# File 'lib/cocot/cocot.rb', line 8

def initialize
  @salida = SalidaEstándar.new($stdout)
end

Instance Attribute Details

#juzgador_de_argumentosObject (readonly)

Returns the value of attribute juzgador_de_argumentos.



6
7
8
# File 'lib/cocot/cocot.rb', line 6

def juzgador_de_argumentos
  @juzgador_de_argumentos
end

#salidaObject (readonly)

Returns the value of attribute salida.



6
7
8
# File 'lib/cocot/cocot.rb', line 6

def salida
  @salida
end

Instance Method Details

#accionarObject

El “accionar” de parte del programa se da una sola vez, luego del interrogatorio al juzgador.



37
38
39
40
41
42
43
44
# File 'lib/cocot/cocot.rb', line 37

def accionar
  exit(false) if @error_existente
  exit(true) if @ayuda_invocada
  #llegado a este punto se entiende que el usuario ingresó correctamente el comando de inicio, aunqué puede que el constructor de esqueleto encuentre un problema
  unless construir_esqueleto() then exit(false) end
  #todo anduvo bien
  true
end

#construir_esqueletoObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cocot/cocot.rb', line 46

def construir_esqueleto
  @constructor_de_esqueleto = ConstructorDeEsqueleto.new
  #si la siguiente acción tiene éxito devuelve true, de otra forma false, lo cual quiere decir que hubo un problema
  if @constructor_de_esqueleto.construir_esqueleto(@nombre_del_proyecto)
    @salida.escribir("Structure built. Have fun developing! :)\n")
    true
  else
    @salida.escribir(@constructor_de_esqueleto.explicar_inconveniente)
    false
  end
end

#interrogar_juzgadorObject

Interroga al juzgador de argumentos en búsqueda de saber si hubo algún error en ellos.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cocot/cocot.rb', line 24

def interrogar_juzgador
  if @juzgador_de_argumentos.hubo_algun_error?
    @error_existente = true
    @salida.escribir(@juzgador_de_argumentos.describime_el_error)
  elsif @juzgador_de_argumentos.fue_la_ayuda_solicitada?
    @ayuda_invocada = true
    mostrar_ayuda_en_pantalla()
  else
    @salida.escribir("Building skeletal structure for #{@nombre_del_proyecto = @juzgador_de_argumentos.cual_será_el_nombre_del_proyecto?}.\n")
  end
end

#juzgar_argumentosObject

Parameters:

  • argumentos (Array)

    .



18
19
20
21
# File 'lib/cocot/cocot.rb', line 18

def juzgar_argumentos
  @juzgador_de_argumentos = JuzgadorDeArgumentos.new #: JuzgadorDeArgumentos
  @juzgador_de_argumentos.juzgar_argumentos(@argumentos)
end

#limpiar_argumentos(argumentos) ⇒ Object

Parameters:

  • argumentos (Array)

    . Se quieren limpiar todos aquellos argumentos vacíos, como por ejemplo aquellos que surgen al pasar ” o “” en la línea de comandos.



13
14
15
# File 'lib/cocot/cocot.rb', line 13

def limpiar_argumentos(argumentos)
  @argumentos = argumentos.select {|arg| arg.strip.length.!=(0)} #: Array
end

#mostrar_ayuda_en_pantallaObject



58
59
60
61
# File 'lib/cocot/cocot.rb', line 58

def mostrar_ayuda_en_pantalla
  msj_de_ayuda = " cocot builds the skeleton layout of your BDD proyects.\n\n You just have to give him the name of your proyect like this: `cocot \"name of the proyect\"`.\n\n You can pass around these options:\n\n --full\t\t\tBuild extra folders suchs as \"data\", \"share\" and \"ext\".\n\n The next options works as solo and can be combined with previous one:\n\n --rspec-only\t\tStandard skeleton + folders and files needed to work with RSpec.\n --cucumber-only\tStandard skeleton + folders and files needed to work with Cucumber.\n --minitest-only\tStandard skeleton + folders and files needed to work with minitest.\n --clean\t\tStandard skeleton.\n\n If you don't use any of the previous 4 options cocot will build the standard skeleton plus folders and files needed to work with Cucumber and RSpec."
  @salida.escribir(msj_de_ayuda)
end