Class: Cucumber::CucumberExpressions::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/cucumber_expressions/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, nodes, token, start, ending) ⇒ Node

Returns a new instance of Node.



15
16
17
18
19
20
21
22
23
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 15

def initialize(type, nodes, token, start, ending)
  raise 'Either nodes or token must be defined' if nodes.nil? && token.nil?

  @type = type
  @nodes = nodes
  @token = token
  @start = start
  @end = ending
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



13
14
15
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 13

def end
  @end
end

#nodesObject (readonly)

Returns the value of attribute nodes.



13
14
15
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 13

def nodes
  @nodes
end

#startObject (readonly)

Returns the value of attribute start.



13
14
15
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 13

def start
  @start
end

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 13

def token
  @token
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 13

def type
  @type
end

Instance Method Details

#textObject



25
26
27
28
29
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 25

def text
  return @nodes.map { |value| value.text }.join('') if @token.nil?

  @token
end

#to_hashObject



31
32
33
34
35
36
37
38
39
# File 'lib/cucumber/cucumber_expressions/ast.rb', line 31

def to_hash
  hash = Hash.new
  hash['type'] = @type
  hash['nodes'] = @nodes.map { |node| node.to_hash } unless @nodes.nil?
  hash['token'] = @token unless @token.nil?
  hash['start'] = @start
  hash['end'] = @end
  hash
end