Class: Atributo

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/fold/atributo.rb

Constant Summary collapse

CLASES =
[:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean, :references]
VALORES =
[:true, :false, :nil]
OPCIONES =
[:unique, :index, :polymorphic]
ANCHO =
15

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Atributo

Returns a new instance of Atributo.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/fold/atributo.rb', line 9

def initialize(s)
  parametros = s.split(':')

  @nombre = parametros.shift
  @clase = :string if parametros.empty?
  @opciones = []

  parametros.each do |parametro|
    incluir parametro.to_sym
  end

end

Instance Attribute Details

#claseObject

Returns the value of attribute clase.



7
8
9
# File 'lib/generators/fold/atributo.rb', line 7

def clase
  @clase
end

#defaultObject

Returns the value of attribute default.



7
8
9
# File 'lib/generators/fold/atributo.rb', line 7

def default
  @default
end

#nombreObject

Returns the value of attribute nombre.



7
8
9
# File 'lib/generators/fold/atributo.rb', line 7

def nombre
  @nombre
end

#opcionesObject

Returns the value of attribute opciones.



7
8
9
# File 'lib/generators/fold/atributo.rb', line 7

def opciones
  @opciones
end

Instance Method Details

#ejemploObject



45
46
47
48
49
50
51
52
# File 'lib/generators/fold/atributo.rb', line 45

def ejemplo
  case @clase
  when :string   then "'Lorem Ipsum'"
  when :integer  then rand(50)
  when :boolean  then 'true'      
  else false
  end
end

#es?(opcion) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/generators/fold/atributo.rb', line 37

def es?(opcion)
  @opciones.include? opcion
end

#incluir(parametro) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/fold/atributo.rb', line 22

def incluir(parametro)
  if CLASES.include? parametro
    @clase = parametro
  end

  if VALORES.include? parametro
    @clase ||= :boolean
    @default = parametro
  end

  if OPCIONES.include? parametro
    @opciones << parametro
  end
end

#tiene_opciones?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/generators/fold/atributo.rb', line 41

def tiene_opciones?
  ! @opciones.empty?
end