Class: General::GText

Inherits:
GPartial show all
Defined in:
lib/gpartials/gtext.rb

Overview

Created: 7 - 1 - 2016

Direct Known Subclasses

GSpecial

Constant Summary collapse

REGEX =

Regular expression that matches text partials

/\A[^@]+?(?=(@|\z))/m
PTNAME =

The partial name of a text

:__text

Instance Attribute Summary

Attributes inherited from GPartial

#name

Instance Method Summary collapse

Constructor Details

#initialize(match, defaults = {}) ⇒ GText

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



39
40
41
42
# File 'lib/gpartials/gtext.rb', line 39

def initialize match, defaults={}
	super({name: PTNAME}, defaults)
	@text = match.to_s
end

Instance Method Details

#apply(data) ⇒ Object

Returns the text

Parameter: data - the data to apply to the partial

Returns: the text



49
# File 'lib/gpartials/gtext.rb', line 49

def apply(data); @text; end

#regex(first = true) ⇒ Object

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



63
# File 'lib/gpartials/gtext.rb', line 63

def regex(first=true); @text.inspect[1...-1].gsub(/[\.\+\-\*]/) { |s| "\\#{s}" }; end

#string(first = true) ⇒ Object

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



56
# File 'lib/gpartials/gtext.rb', line 56

def string(first=true); @text.inspect[1...-1]; end