Class: HTM::Timeframe
- Inherits:
-
Object
- Object
- HTM::Timeframe
- Defined in:
- lib/htm/timeframe.rb
Overview
Timeframe - Normalizes various timeframe inputs for database queries
Handles multiple input types and normalizes them to either:
- nil (no timeframe filter)
- Range (single time window)
- Array
(multiple time windows, OR'd together)
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.normalize(input, query: nil) ⇒ nil, ...
Normalize a timeframe input to nil, Range, or Array
. -
.valid?(input) ⇒ Boolean
Check if a value is a valid timeframe input.
Class Method Details
.normalize(input, query: nil) ⇒ nil, ...
Normalize a timeframe input to nil, Range, or Array
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/htm/timeframe.rb', line 35 def normalize(input, query: nil) case input when nil nil when :auto normalize_auto(query) when Range validate_range!(input) input when Array normalize_array(input) when Date normalize_date(input) when DateTime normalize_datetime(input) when Time normalize_time(input) when String normalize_string(input) else raise ArgumentError, "Unsupported timeframe type: #{input.class}. " \ "Expected nil, Range, Array<Range>, Date, DateTime, Time, String, or :auto" end end |
.valid?(input) ⇒ Boolean
Check if a value is a valid timeframe input
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/htm/timeframe.rb', line 73 def valid?(input) case input when nil, :auto, Range, Date, DateTime, Time, String true when Array input.all?(Range) else false end end |