Class: LtdTemplate::Proxy::Boolean

Inherits:
LtdTemplate::Proxy show all
Defined in:
lib/ltdtemplate/proxy/boolean.rb

Instance Attribute Summary

Attributes included from Value

#runtime_methods

Instance Method Summary collapse

Methods inherited from LtdTemplate::Proxy

#initialize, #rubyverse_original, #rubyversed

Methods included from Value

#do_methods, #do_run_method, included, #initialize, #inspect, #rubyversed

Constructor Details

This class inherits a constructor from LtdTemplate::Proxy

Instance Method Details

#do_and(opts) ⇒ Object

Implement */& (and): bool&(bool1, …, boolN) True if ALL booleans are true. Evaluates {} blocks until false.



49
50
51
52
53
54
55
56
57
58
# File 'lib/ltdtemplate/proxy/boolean.rb', line 49

def do_and (opts)
	if @original && (params = opts[:parameters])
 params.each(:seq) do |idx, expr|
		return false unless rubyversed(expr).
evaluate(:method => 'call').in_rubyverse(@template).
tpl_boolean
 end
	end
	@original
end

#do_not(opts) ⇒ Object

Implement ! (not): bool!(bool1, …, boolN) True if ALL booleans are false. Evaluates {} blocks until true.



63
64
65
66
67
68
69
70
71
72
# File 'lib/ltdtemplate/proxy/boolean.rb', line 63

def do_not (opts)
	if !@original && (params = opts[:parameters])
 params.each(:seq) do |idx, expr|
		return false if rubyversed(expr).
evaluate(:method => 'call').in_rubyverse(@template).
to_boolean
 end
	end
	!@original
end

#do_or(opts) ⇒ Object

Implement +/| (or): bool|(bool1, …, boolN) True if ANY boolean is true. Evaluates {} blocks until true.



36
37
38
39
40
41
42
43
44
# File 'lib/ltdtemplate/proxy/boolean.rb', line 36

def do_or (opts)
	if !@original && (params = opts[:parameters])
 params.each(:seq) do |idx, expr|
		return true if rubyversed(expr).evaluate(:method => 'call').
in_rubyverse(@template).tpl_boolean
 end
	end
	@original
end

#evaluate(opts = {}) ⇒ Object

Evaluate supported methods on boolean objects.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ltdtemplate/proxy/boolean.rb', line 12

def evaluate (opts = {})
	case opts[:method]
	when nil, 'call' then @original
	when 'class' then 'Boolean'
	when 'str', 'string' then @original ? 'true' : 'false'
	when 'type' then 'boolean'
	when '+', '|', 'or' then do_or opts
	when '*', '&', 'and' then do_and opts
	when '!', 'not' then do_not opts
	else super opts
	end
end

#tpl_booleanObject

The template boolean value is the same as the original boolean value.



26
# File 'lib/ltdtemplate/proxy/boolean.rb', line 26

def tpl_boolean; @original; end

#tpl_textObject

Booleans have no textual value in templates.



29
# File 'lib/ltdtemplate/proxy/boolean.rb', line 29

def tpl_text; ''; end