4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ProMotion/XLForm/xl_form_helper.rb', line 4
def configure_hidden(cell_or_section, predicate)
tag = operand = value = nil
if predicate.is_a?(Hash)
tag = predicate[:name]
operand = case predicate[:is]
when :equal
'=='
when :not_equal
'!='
when :contains
'contains'
when :not_contains
'not contains'
else
predicate[:is]
end
value = predicate[:value]
else
match = /(:?[a-zA-Z_]+)\s+(==|!=|contains|not contains)\s+(.*)/.match(predicate)
if match && match.length == 4
tag = match[1]
operand = match[2]
value = match[3]
if value =~ /"(.*)"/
value = value[1, value.length - 2]
end
end
end
if tag && operand
if tag.is_a?(Symbol)
tag = tag.to_s
elsif tag.start_with?(':')
tag[0] = ''
end
tag += ".value.valueData" if predicate.is_a?(Hash) && predicate[:options]
value = case value
when nil
'nil'
when 'true', :true, true
0
when 'false', :false, false
1
when String
"\"#{value}\""
else
value
end
if operand == 'contains'
cell_or_section.hidden = "$#{tag} contains[c] #{value}"
elsif operand == 'not contains'
cell_or_section.hidden = "not($#{tag} contains[c] #{value})"
else
cell_or_section.hidden = "$#{tag} #{operand} #{value}"
end
else
mp predicate: predicate.inspect, message: "predicate can not be parsed", force_color: :red
end
end
|