Class: Axe::API::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/axe/api/rules.rb

Instance Method Summary collapse

Constructor Details

#initializeRules

Returns a new instance of Rules.



4
5
6
7
8
9
# File 'lib/axe/api/rules.rb', line 4

def initialize
  @tags = []
  @included = []
  @excluded = []
  @exclusive = []
end

Instance Method Details

#according_to(*tags) ⇒ Object



11
12
13
# File 'lib/axe/api/rules.rb', line 11

def according_to(*tags)
  @tags.concat tags.flatten
end

#checking(*rules) ⇒ Object



15
16
17
# File 'lib/axe/api/rules.rb', line 15

def checking(*rules)
  @included.concat rules.flatten
end

#checking_only(*rules) ⇒ Object



19
20
21
# File 'lib/axe/api/rules.rb', line 19

def checking_only(*rules)
  @exclusive.concat rules.flatten
end

#skipping(*rules) ⇒ Object



23
24
25
# File 'lib/axe/api/rules.rb', line 23

def skipping(*rules)
  @excluded.concat rules.flatten
end

#to_hashObject



27
28
29
30
31
32
33
34
# File 'lib/axe/api/rules.rb', line 27

def to_hash
  {}.tap do |options|
    # TODO warn that tags + exclusive-rules are incompatible
    options.merge! runOnly: { type: :tag, values: @tags } unless @tags.empty?
    options.merge! runOnly: { type: :rule, values: @exclusive } unless @exclusive.empty?
    options.merge! rules: Hash[@included.product([enabled: true]) + @excluded.product([enabled: false])] unless @included.empty? && @excluded.empty?
  end
end