Class: LtdTemplate::Proxy::Regexp

Inherits:
LtdTemplate::Proxy show all
Defined in:
lib/ltdtemplate/proxy/regexp.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, #tpl_boolean

Constructor Details

This class inherits a constructor from LtdTemplate::Proxy

Instance Method Details

#do_match(opts) ⇒ Object



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

def do_match (opts)
	if (params = opts[:parameters]) && params.size(:seq) > 0 &&
	  params[0].is_a?(::String)
 # Track array size generated??
 @original.match(*params[0..1].values)
	else nil
	end
end

#evaluate(opts = {}) ⇒ Object

Evaluate supported methods on Regexp (regular expression) objects.



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
# File 'lib/ltdtemplate/proxy/regexp.rb', line 12

def evaluate (opts = {})
	# These methods are supported regardless of whether regexp
	# is enabled.
	case opts[:method]
	when nil, 'call'
 if @template.options[:regexp] then return @original
 else return nil
 end
	when 'class' then return 'Regexp'
	when 'str', 'string'
 return @original.to_s.tap do |str|
		# RESOURCE string_total: Combined length of computed strings
		@template.use :string_total, str.size
		# RESOURCE string_length: Length of longest modified string
		@template.using :string_length, str.size
 end
	when 'type' then return 'regexp'
	end

	# These methods are disabled unless regexp is enabled.
	if @template.options[:regexp]
 case opts[:method]
 when 'ci', 'ignorecase'
		if (@original.options & ::Regexp::IGNORECASE) != 0
  return @original
		else return ::Regexp.new(@original.source,
@original.options | ::Regexp::IGNORECASE)
		end
 when 'ext', 'extended'
		if (@original.options & ::Regexp::EXTENDED) != 0
  return @original
		else return ::Regexp.new(@original.source,
@original.options | ::Regexp::EXTENDED)
		end
 when 'match' then return do_match opts
 when 'multi', 'multiline'
		if (@original.options & ::Regexp::MULTILINE) != 0
  return @original
		else return ::Regexp.new(@original.source,
@original.options | ::Regexp::MULTILINE)
		end
 end
	end

	super opts
end

#tpl_textObject



59
# File 'lib/ltdtemplate/proxy/regexp.rb', line 59

def tpl_text; ''; end