Class: Axe::API::Context

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

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



6
7
8
9
# File 'lib/axe/api/context.rb', line 6

def initialize
  @inclusion = []
  @exclusion = []
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/axe/api/context.rb', line 34

def empty?
  to_hash.empty?
end

#excluding(*selectors) ⇒ Object



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

def excluding(*selectors)
  @exclusion.concat selectors.map { |s| Selector::normalize s }
end

#to_hObject



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

def to_h
  to_hash
end

#to_hashObject



22
23
24
25
26
27
28
# File 'lib/axe/api/context.rb', line 22

def to_hash
  return { exclude: @exclusion } if @inclusion.empty?
  h = {}
  h["include"] = @inclusion unless @inclusion.empty?
  h["exclude"] = @exclusion unless @exclusion.empty?
  h
end

#to_json(options = nil) ⇒ Object Also known as: to_s



30
31
32
# File 'lib/axe/api/context.rb', line 30

def to_json(options = nil)
  to_hash.to_json options
end

#within(*selectors) ⇒ Object



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

def within(*selectors)
  @inclusion.concat selectors.map { |s| Selector::normalize s }
end