class General::GText
Represents a plain text partial in a GTemplate
Author: Anshul Kharbanda Created: 7 - 1 - 2016
Constants
- PTNAME
The partial name of a text
- REGEX
Regular expression that matches text partials
Public Class Methods
new(match, defaults={})
click to toggle source
Initializes the GText
with the given match
Parameter: match - the match object of the GText
Parameter: defaults - the hash of default data from the GTemplate
Calls superclass method
General::GPartial::new
# File lib/gpartials/gtext.rb, line 39 def initialize match, defaults={} super({name: PTNAME}, defaults) @text = match.to_s end
Public Instance Methods
apply(data)
click to toggle source
Returns the text
Parameter: data - the data to apply to the partial
Returns: the text
# File lib/gpartials/gtext.rb, line 49 def apply(data); @text; end
regex(first=true)
click to toggle source
Returns the text as a regex
Parameter: first - true if this partial is the first of it's kind in a GTemplate
Returns: the text as a regex
# File lib/gpartials/gtext.rb, line 63 def regex(first=true); @text.inspect[1...-1].gsub(/[\.\+\-\*]/) { |s| "\\#{s}" }; end
string(first=true)
click to toggle source
Returns the text as a string
Parameter: first - true if this partial is the first of it's kind in a GTemplate
Returns: the text as a string
# File lib/gpartials/gtext.rb, line 56 def string(first=true); @text.inspect[1...-1]; end