Class: Atributo
- Inherits:
-
Object
- Object
- Atributo
- 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
-
#clase ⇒ Object
Returns the value of attribute clase.
-
#default ⇒ Object
Returns the value of attribute default.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
-
#opciones ⇒ Object
Returns the value of attribute opciones.
Instance Method Summary collapse
- #ejemplo ⇒ Object
- #es?(opcion) ⇒ Boolean
- #incluir(parametro) ⇒ Object
-
#initialize(s) ⇒ Atributo
constructor
A new instance of Atributo.
- #tiene_opciones? ⇒ Boolean
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
#clase ⇒ Object
Returns the value of attribute clase.
7 8 9 |
# File 'lib/generators/fold/atributo.rb', line 7 def clase @clase end |
#default ⇒ Object
Returns the value of attribute default.
7 8 9 |
# File 'lib/generators/fold/atributo.rb', line 7 def default @default end |
#nombre ⇒ Object
Returns the value of attribute nombre.
7 8 9 |
# File 'lib/generators/fold/atributo.rb', line 7 def nombre @nombre end |
#opciones ⇒ Object
Returns the value of attribute opciones.
7 8 9 |
# File 'lib/generators/fold/atributo.rb', line 7 def opciones @opciones end |
Instance Method Details
#ejemplo ⇒ Object
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
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
41 42 43 |
# File 'lib/generators/fold/atributo.rb', line 41 def tiene_opciones? ! @opciones.empty? end |