Module: Toller::Filters::Mutators::Datetime

Defined in:
lib/toller/filters/mutators/datetime.rb

Overview

Datetime filter mutator

Class Method Summary collapse

Class Method Details

.call(value) ⇒ String, Range

Coerces a raw filter param into a datetime value or range.

Parameters:

  • value (String)

    the raw filter param value

Returns:

  • (String, Range)

    the original value, or a Range when the value contains range syntax (.. or ...)



18
19
20
21
22
23
24
# File 'lib/toller/filters/mutators/datetime.rb', line 18

def call(value)
  range_dots = inclusive_or_exclusive_range(value)

  return value if range_dots.blank?

  range(value, range_dots)
end

.inclusive_or_exclusive_range(value) ⇒ String?

Detects whether value contains inclusive or exclusive range syntax.

Parameters:

  • value (String)

    the raw filter param value

Returns:

  • (String, nil)

    "..." for an exclusive range, ".." for an inclusive range, or nil if value is not a range



42
43
44
45
46
47
# File 'lib/toller/filters/mutators/datetime.rb', line 42

def inclusive_or_exclusive_range(value)
  return "..." if value.include?("...")
  return ".." if value.include?("..")

  nil
end

.range(value, dots) ⇒ Range

Builds a Range by splitting value on the given range dots.

Parameters:

  • value (String)

    the raw range string, e.g. "2024-01-01..2024-12-31"

  • dots (String)

    the range separator, either ".." or "..."

Returns:

  • (Range)

    the resulting range



32
33
34
# File 'lib/toller/filters/mutators/datetime.rb', line 32

def range(value, dots)
  Range.new(*value.split(dots))
end