Module: DecisionAgent::Dsl::Operators::TimeComponentOperators
- Defined in:
- lib/decision_agent/dsl/operators/time_component_operators.rb
Overview
Handles time component extraction operators: hour_of_day, day_of_month, month, year, week_of_year
Class Method Summary collapse
-
.compare_numeric_result(actual, expected) ⇒ Object
Compare numeric result (for time component extraction).
- .handle(op, actual_value, expected_value) ⇒ Object
Class Method Details
.compare_numeric_result(actual, expected) ⇒ Object
Compare numeric result (for time component extraction)
64 65 66 67 68 |
# File 'lib/decision_agent/dsl/operators/time_component_operators.rb', line 64 def self.compare_numeric_result(actual, expected) return actual == expected unless expected.is_a?(Hash) Helpers::ComparisonHelpers.compare_numeric_with_hash(actual, expected) end |
.handle(op, actual_value, expected_value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/decision_agent/dsl/operators/time_component_operators.rb', line 8 def self.handle(op, actual_value, expected_value) case op when "hour_of_day" # Extracts hour of day (0-23) and compares return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date hour = date.hour compare_numeric_result(hour, expected_value) when "day_of_month" # Extracts day of month (1-31) and compares return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date day = date.day compare_numeric_result(day, expected_value) when "month" # Extracts month (1-12) and compares return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date month = date.month compare_numeric_result(month, expected_value) when "year" # Extracts year and compares return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date year = date.year compare_numeric_result(year, expected_value) when "week_of_year" # Extracts week of year (1-52) and compares return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date week = date.strftime("%U").to_i + 1 # %U returns 0-53, we want 1-53 compare_numeric_result(week, expected_value) end # Returns nil if not handled by this module end |