Class: CodelessCode::Filters::Date

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

Overview

Matches fables that were published on, before, or after a given date.

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Constructor Details

#initialize(exact: nil, min: nil, max: nil, exclude: false) ⇒ Date

:reek:BooleanParameter


26
27
28
29
30
31
32
33
# File 'lib/codeless_code/filters/date.rb', line 26

def initialize(exact: nil, min: nil, max: nil, exclude: false)
  @tests ||= [
    [exact, :==],
    [min,   :>=],
    [max,   :<=]
  ].select(&:first).freeze
  @exclude = exclude
end

Instance Method Details

#call(fable) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/codeless_code/filters/date.rb', line 39

def call(fable)
  if (val = fable.date)
    @tests.any? ? test(val) : !@exclude
  else
    @exclude
  end
end

#enabled?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/codeless_code/filters/date.rb', line 35

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