Class: Lucid::AST::Feature

Inherits:
Object show all
Includes:
HasLocation, Names
Defined in:
lib/lucid/ast/feature.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes included from Names

#description, #title

Instance Method Summary collapse

Methods included from HasLocation

#file, #file_colon_line, #line, #location

Methods included from Names

#name

Constructor Details

#initialize(location, background, comment, tags, keyword, title, description, feature_elements) ⇒ Feature

Returns a new instance of Feature.



16
17
18
19
20
21
# File 'lib/lucid/ast/feature.rb', line 16

def initialize(location, background, comment, tags, keyword, title, description, feature_elements)
  @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
  @background.feature = self
  @location = location
  @feature_elements.each { |e| e.feature = self }
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



14
15
16
# File 'lib/lucid/ast/feature.rb', line 14

def comment
  @comment
end

#feature_elementsObject (readonly)

Returns the value of attribute feature_elements.



13
14
15
# File 'lib/lucid/ast/feature.rb', line 13

def feature_elements
  @feature_elements
end

#gherkin_statement(statement = nil) ⇒ Object (readonly)

Returns the value of attribute gherkin_statement.



23
24
25
# File 'lib/lucid/ast/feature.rb', line 23

def gherkin_statement
  @gherkin_statement
end

#languageObject

Returns the value of attribute language.



12
13
14
# File 'lib/lucid/ast/feature.rb', line 12

def language
  @language
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/lucid/ast/feature.rb', line 14

def tags
  @tags
end

Instance Method Details

#accept(visitor) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/lucid/ast/feature.rb', line 32

def accept(visitor)
  visitor.visit_feature(self) do
    comment.accept(visitor)
    tags.accept(visitor)
    visitor.visit_feature_name(@keyword, indented_name)
    @feature_elements.each do |feature_element|
      feature_element.accept(visitor)
    end
  end
end

#accept_hook?(hook) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/lucid/ast/feature.rb', line 60

def accept_hook?(hook)
  @tags.accept_hook?(hook)
end

#backtrace_line(step_name, line) ⇒ Object



64
65
66
# File 'lib/lucid/ast/feature.rb', line 64

def backtrace_line(step_name, line)
  "#{location.on_line(line)}:in `#{step_name}'"
end

#indented_nameObject



43
44
45
46
47
48
49
50
# File 'lib/lucid/ast/feature.rb', line 43

def indented_name
  indent = ""
  name.split("\n").map do |l|
    s = "#{indent}#{l}"
    indent = "  "
    s
  end.join("\n")
end

#short_nameObject



68
69
70
71
72
73
74
75
# File 'lib/lucid/ast/feature.rb', line 68

def short_name
  first_line = name.split(/\n/)[0]
  if first_line =~ /#{language.keywords('feature')}:(.*)/
    $1.strip
  else
    first_line
  end
end

#source_tag_namesObject



56
57
58
# File 'lib/lucid/ast/feature.rb', line 56

def source_tag_names
  source_tags.map { |tag| tag.name }
end

#source_tagsObject



52
53
54
# File 'lib/lucid/ast/feature.rb', line 52

def source_tags
  @tags.tags
end

#step_countObject



28
29
30
# File 'lib/lucid/ast/feature.rb', line 28

def step_count
  units.inject(0) { |total, unit| total += unit.step_count }
end

#to_sexpObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/lucid/ast/feature.rb', line 77

def to_sexp
  sexp = [:feature, file, name]
  comment = @comment.to_sexp
  sexp += [comment] if comment
  tags = @tags.to_sexp
  sexp += tags if tags.any?
  sexp += [@background.to_sexp] if @background
  sexp += @feature_elements.map{|fe| fe.to_sexp}
  sexp
end