Class: TracLang::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/trac_lang/expression.rb

Overview

Model of TRAC neutral string expression. An expression is an array of strings, corresponding to the arguments of a TRAC expression. Expressions are active if they were called by #(…) and not active (neutral) if they were called by ##(…).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpression

Creates new active expression.



21
22
23
24
# File 'lib/trac_lang/expression.rb', line 21

def initialize
  @args = ['']
  @active = true
end

Instance Attribute Details

#activeObject Also known as: active?

Flag to tell if this expression is active or neutral. The result of active expressions are copied to the active string, while the result of neutral expressions are copied to the enclosing expression.



13
14
15
# File 'lib/trac_lang/expression.rb', line 13

def active
  @active
end

#argsObject

List of arguments for this expression.



16
17
18
# File 'lib/trac_lang/expression.rb', line 16

def args
  @args
end

Instance Method Details

#commandObject

Command for TRAC processor.



27
28
29
# File 'lib/trac_lang/expression.rb', line 27

def command
  @args[0].downcase.to_sym
end

#concat(str) ⇒ Object

Adds a string to current argument of the expression.



37
38
39
# File 'lib/trac_lang/expression.rb', line 37

def concat(str)
  @args.last.concat str
end

#newargObject

Signals a new argument is starting.



42
43
44
# File 'lib/trac_lang/expression.rb', line 42

def newarg
  @args.push ''
end

#sizeObject

Returns current number of arguments in expression.



47
48
49
# File 'lib/trac_lang/expression.rb', line 47

def size
  @args.size
end

#to_sObject

String version of expression, used when trace is on



52
53
54
# File 'lib/trac_lang/expression.rb', line 52

def to_s
  (@active ? '#/' : '##/') + @args.join('*') + '/'
end

#trac_argsObject

Arguments for TRAC command.



32
33
34
# File 'lib/trac_lang/expression.rb', line 32

def trac_args
  @args[1..-1]
end