Class: Rapid::Template::Node::CommentNode

Inherits:
Base
  • Object
show all
Defined in:
lib/rapid/template/node/comment_node.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

#content, #next_node, #next_to, #static?

Constructor Details

#initialize(value, variable) ⇒ CommentNode

Returns a new instance of CommentNode.



9
10
11
12
13
14
15
16
# File 'lib/rapid/template/node/comment_node.rb', line 9

def initialize value, variable
  @value = value
  @variable = variable
  
  if @variable.ends_with? "?"
    @variable = @variable[0..-2]
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/rapid/template/node/comment_node.rb', line 7

def value
  @value
end

#variableObject (readonly)

Returns the value of attribute variable.



7
8
9
# File 'lib/rapid/template/node/comment_node.rb', line 7

def variable
  @variable
end

Instance Method Details

#==(obj) ⇒ Object



28
29
30
31
32
# File 'lib/rapid/template/node/comment_node.rb', line 28

def == obj
  obj.is_a?(self.class) && 
    obj.variable == variable &&
    obj.value == value
end

#inspectObject



34
35
36
# File 'lib/rapid/template/node/comment_node.rb', line 34

def inspect
  %(#<comment @value=#{@value.inspect} @variable=#{@variable.inspect}>)
end

#pull(result) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rapid/template/node/comment_node.rb', line 18

def pull result
  len = result.starts_with "# "
  if len
    result.move! len
    result[variable] = value
  else
    result[variable] = !value
  end
end