5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 04:31:41 +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?
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