NAME

Squirrel::Template::Expr::WrapScalar - provide methods for scalars


SYNOPSIS

  len = somescalar.length;
  upper = somescalar.upper;
  lower = somescalar.lower;
  defd = somescalar.defined;
  trimmed = somescalar.trim;
  split = somescalar.split;
  split = somescalar.split(":");
  split = somescalar.split(":", count);
  formatted = somescalar.format("%05d");
  value = somescalar.evaltag
  quoted = somescalar.quotemeta
  contains = somescalar.contains("foo")
  pos = somescalar.index("foo")
  pos = somescalar.index("foo", 5)
  pos = somescalar.rindex("foo")
  pos = somescalar.rindex("foo", 5)
  char = somenumber.chr
  int = somenumber.int
  random = somenumber.rand
  abs = (-10).abs  # 10
  floor = (-10.1).floor # -11
  ceil = (-10.1).ceil # -10
  somescalar.is_list # always false
  somescalar.is_hash # always false


DESCRIPTION

Provides virtual methods for scalars in the Squirrel::Template manpage expressions.


SCALAR METHODS

length

Return the length of the string in characters.

upper

Return the string in upper case

lower

Return the string in lower case.

defined

Return true if the string has a defined value.

split
split(sep)
split(sep, count)

Return a list object of the string split on the regular expression sep, returning up to count objects. sep defaults to " ", count defaults to 0. A count of 0 returns as many elements as are found but removes any trailing empty length elements. A negative count returns all elements.

evaltag

Evalulate the value of string as if processed as a tag. The string must not include the surrounding <: ... :>.

quotemeta

Return the string with regular expression metacharacters quoted with \.

contains(substring)

Returns true if the subject contains the given substring.

index(substring)
index(substring, start)

Return the position of substring within the subject, searching forward from start or from the beginning of the string. Returns -1 if substring isn't found.

rindex(substring)
rindex(substring, start)

Return the position of substring within the subject, searching backward from start or from the end of the string. Returns -1 if substring isn't found.

replace(regexp, replacement)
replace(regexp, replacement, global)

Replace the given regexp in the string with replacement. $1 etc are replaced with what the corresponding parenthesized expression in the regexp matched. $$ is replaced with $.

If global is present and true, replace every instance.

Does not modify the source, simply returns the modified text.

chr

Convert a character code into a character.

  (65).chr # "A"
int

Convert a number to an integer.

  (10.1).int # 10
rand

Produce a floating point random number greater or equal to 0 and less than the subject.

  (10).rand # 0 <= result < 10
abs

Return the absolute value of the subject.

floor

Return the highest integer less than or equal to the subject

  (10).floor # 10
  (10.1).floor  # 10
  (-10.1).floor # -11
ceil

Return the lowest integer greater than or equal to the subject.

  (10).ceil # 10
  (10.1).ceil # 11
  (-10.1).ceil # -10
is_list

Test if this object is a list. Always true for a list.

is_hash

Test if this object is a hash. Always false for a list.

is_code

Test if this object is a code object.


SEE ALSO

the Squirrel::Template::Expr manpage, the Squirrel::Template manpage


AUTHOR

Tony Cook <tony@develop-help.com>