5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-07 08:35:45 +00:00

convertir a metodos

This commit is contained in:
f 2018-06-15 18:40:22 -03:00
parent 1bcb91b6ec
commit 1d8f1cb0a3
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7

View file

@ -15,21 +15,33 @@ class Post
return unless simple? return unless simple?
case case
when contents == 'string' when text_area?
@type = 'text'
when contents == 'text'
@type = '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' @type = 'select'
when contents.is_a?(Array) when array?
@type = 'select' @type = 'select'
when contents.is_a?(FalseClass) || contents.is_a?(TrueClass) when boolean?
@type = 'check_box' @type = 'check_box'
end end
@type @type
end 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 # Si la plantilla es simple no está admitiendo Hashes como valores
def simple? def simple?
!complex? !complex?
@ -44,6 +56,7 @@ class Post
key key
end end
# Convierte el campo en un parámetro
def to_param def to_param
if array? if array?
{ key.to_sym => [] } { key.to_sym => [] }
@ -53,7 +66,7 @@ class Post
end end
def array? def array?
@contents.is_a? Array contents.is_a? Array
end end
# TODO detectar cuando es complejo y tomar el valor de :multiple # TODO detectar cuando es complejo y tomar el valor de :multiple
@ -62,7 +75,7 @@ class Post
end end
def value def value
@contents contents
end end
# Obtiene los valores posibles para el campo de la plantilla # Obtiene los valores posibles para el campo de la plantilla