From 1d8f1cb0a324a0c12650a0e1976db403b0fec960 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 15 Jun 2018 18:40:22 -0300 Subject: [PATCH] convertir a metodos --- app/models/post/template_field.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index 4f5abc3..6a98422 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -15,21 +15,33 @@ class Post return unless simple? case - when contents == 'string' - @type = 'text' - when contents == 'text' + when text_area? @type = 'text_area' - when contents.is_a?(String) && contents.split('/', 2).count == 2 + when string? + @type = 'text' + when string? && contents.split('/', 2).count == 2 @type = 'select' - when contents.is_a?(Array) + when array? @type = 'select' - when contents.is_a?(FalseClass) || contents.is_a?(TrueClass) + when boolean? @type = 'check_box' end @type end + def boolean? + contents.is_a?(FalseClass) || contents.is_a?(TrueClass) + end + + def string? + contents.is_a? String + end + + def text_area? + contents == 'text' + end + # Si la plantilla es simple no está admitiendo Hashes como valores def simple? !complex? @@ -44,6 +56,7 @@ class Post key end + # Convierte el campo en un parámetro def to_param if array? { key.to_sym => [] } @@ -53,7 +66,7 @@ class Post end def array? - @contents.is_a? Array + contents.is_a? Array end # TODO detectar cuando es complejo y tomar el valor de :multiple @@ -62,7 +75,7 @@ class Post end def value - @contents + contents end # Obtiene los valores posibles para el campo de la plantilla