Class: Cucumber::Ast::Tags

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

Overview

Holds the names of tags parsed from a feature file:

@invoice @release_2

This gets stored internally as ["invoice", "release_2"]

Instance Method Summary collapse

Constructor Details

#initialize(line, tag_names) ⇒ Tags

Returns a new instance of Tags.



10
11
12
# File 'lib/cucumber/ast/tags.rb', line 10

def initialize(line, tag_names)
  @line, @tag_names = line, tag_names
end

Instance Method Details

#accept(visitor) ⇒ Object



29
30
31
32
33
# File 'lib/cucumber/ast/tags.rb', line 29

def accept(visitor)
  @tag_names.each do |tag_name|
    visitor.visit_tag_name(tag_name)
  end
end

#among?(tag_names) ⇒ Boolean

Returns:

  • (Boolean)


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

def among?(tag_names)
  no_tags, yes_tags = tag_names.partition{|tag| tag =~ /^~/}
  no_tags = no_tags.map{|tag| tag[1..-1]}

  # Strip @
  yes_tags = yes_tags.map{|tag| tag =~ /^@(.*)/ ? $1 : tag}
  no_tags = no_tags.map{|tag| tag =~ /^@(.*)/ ? $1 : tag}

  (yes_tags.empty? || (@tag_names & yes_tags).any?) && (no_tags.empty? || (@tag_names & no_tags).empty?)
end

#at_lines?(lines) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/cucumber/ast/tags.rb', line 25

def at_lines?(lines)
  lines.empty? || lines.index(@line)
end

#to_sexpObject



35
36
37
# File 'lib/cucumber/ast/tags.rb', line 35

def to_sexp
  @tag_names.map{|tag_name| [:tag, tag_name]}
end