Class: CodelessCode::Filters::Headers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/filters/headers/base.rb

Overview

Abstract base class for all generic filters that test a fable's headers.

Direct Known Subclasses

Integer, String

Instance Method Summary collapse

Constructor Details

#initialize(key, exclude, *tests) ⇒ Base

Returns a new instance of Base


24
25
26
27
28
# File 'lib/codeless_code/filters/headers/base.rb', line 24

def initialize(key, exclude, *tests)
  @key = key
  @exclude = exclude
  @tests ||= tests.select(&:first).freeze
end

Instance Method Details

#call(fable) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/codeless_code/filters/headers/base.rb', line 34

def call(fable)
  if fable.header?(@key)
    @tests.any? ? test(parse(fable[@key])) : !@exclude
  else
    @exclude
  end
end

#enabled?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/codeless_code/filters/headers/base.rb', line 30

def enabled?
  @tests.any? || @exclude
end