Class: General::GSpecial

Inherits:
GText show all
Defined in:
lib/gpartials/gspecial.rb

Overview

Created: 7 - 29 - 2016

Constant Summary collapse

REGEX =

Regular expression that matches special partials

/\A@(?<key>\w+)\;/
SPECIALS =

Special character information

{
	at: "@",  pd: "#",
	lt: "<",  gt: ">",
	op: "(",  cp: ")",
	ob: "[",  cb: "]",
	oc: "{",  cc: "}",
	ms: "-",  ps: "+", 
	st: "*",  pc: "%",
	bs: "\\", fs: "/",
	dl: "$"
}
REGEXES =

Special regex information

{
	at: /@/,   pd: /#/,
	lt: /\</, gt: /\>/,
	op: /\(/, cp: /\)/,
	ob: /\[/, cb: /\]/,
	oc: /\{/, cc: /\}/,
	ms: /\-/, ps: /\+/, 
	st: /\*/, pc: /\%/,
	bs: /\\/, fs: /\//,
	dl: /\$/
}

Constants inherited from GText

General::GText::PTNAME

Instance Attribute Summary

Attributes inherited from GPartial

#name

Instance Method Summary collapse

Methods inherited from GText

#apply

Constructor Details

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

Initializes the GSpecial with the given match

Parameter: match - the match object of the GSpecial Parameter: defaults - the hash of default data from the GTemplate



62
63
64
65
# File 'lib/gpartials/gspecial.rb', line 62

def initialize(match, defaults={})
	super SPECIALS[match[:key].to_sym], {}
	@key = match[:key].to_sym
end

Instance Method Details

#regex(first = true) ⇒ Object

Returns the GSpecial as a regex

Parameter: first - true if this partial is the first of it’s kind in a GTemplate

Returns: the GSpecial as a regex



79
# File 'lib/gpartials/gspecial.rb', line 79

def regex(first=true); REGEXES[@key]; end

#string(first = true) ⇒ Object

Returns the string representation of the GSpecial

Parameter: first - true if this partial is the first of it’s kind in a GTemplate

Returns: the string representation of the GSpecial



72
# File 'lib/gpartials/gspecial.rb', line 72

def string(first=true); "@#{@key.to_s};"; end