Class: Cucumber::TagExpression

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTagExpression

Returns a new instance of TagExpression.



9
10
11
12
# File 'lib/cucumber/tag_expression.rb', line 9

def initialize
  @ands = []
  @limits = {}
end

Instance Attribute Details

#limitsObject (readonly)

Returns the value of attribute limits.



3
4
5
# File 'lib/cucumber/tag_expression.rb', line 3

def limits
  @limits
end

Class Method Details

.parse(tag_expressions) ⇒ Object



5
6
7
# File 'lib/cucumber/tag_expression.rb', line 5

def self.parse(tag_expressions)
  tag_expressions.inject(TagExpression.new) { |e, expr| e.add(expr.strip.split(/\s*,\s*/)); e }
end

Instance Method Details

#add(tags) ⇒ Object



14
15
16
17
18
19
# File 'lib/cucumber/tag_expression.rb', line 14

def add(tags)
  negatives, positives = tags.partition{|tag| tag =~ /^~/}
  positive_limits = Hash[*positives.map{|positive| tag, limit = positive.split(':'); [tag, limit ? limit.to_i : nil]}.flatten]
  @limits.merge!(positive_limits)
  @ands << (negatives + positive_limits.keys)
end

#eval(tags) ⇒ Object



21
22
23
24
25
# File 'lib/cucumber/tag_expression.rb', line 21

def eval(tags)
  return true if @ands.flatten.empty?
  vars = Hash[*tags.map{|tag| [tag, true]}.flatten]
  !!Kernel.eval(ruby_expression)
end