module Crystime::Helpers
Overview
Collection of helpers independent of VirtualTime or Item, and which work solely based on their input parameters.
Defined in:
crystime/helpers.crConstant Summary
-
I2M =
M2I.invert
-
I2W =
W2I.invert
-
M2I =
{"JAN" => 1, "FEB" => 2, "MAR" => 3, "APR" => 4, "MAY" => 5, "JUN" => 6, "JUL" => 7, "AUG" => 8, "SEP" => 9, "OCT" => 10, "NOV" => 11, "DEC" => 12}
-
Maps months to integers and vice-versa, and provides a regex for scanning for them in strings.
-
MR =
Regex.new(("\\b(" + (M2I.keys.map(&->Regex.escape(String)).join('|'))) + ")\\b")
-
W2I =
{"SUN" => 0, "MON" => 1, "TUE" => 2, "WED" => 3, "THU" => 4, "FRI" => 5, "SAT" => 6}
-
Maps days of week to integers and vice-versa, and provides a regex for scanning for them in strings.
-
WR =
Regex.new(("\\b(" + (W2I.keys.map(&->Regex.escape(String)).join('|'))) + ")\\b")
Class Method Summary
-
.check(rule, value, fold = nil)
Checks if rule matches value, i.e.
-
.compare(a : Enumerable(Int), b : Enumerable(Int))
Compares all types of accepted values for T and/or VT against each other.
- .compare(a : Proc(Int32, Bool), b : Int)
- .compare(a : Int, b : Proc(Int32, Bool))
- .compare(a : Enumerable(Int), b : Int)
- .compare(a : Nil, b)
- .compare(a, b : Nil)
- .compare(a : Int, b : Enumerable(Int))
- .compare(a, b)
-
.find_day_of_week(str)
Scans for day of week name mentioned in string, and if found, returns that name.
-
.find_month(str)
Scans for month name mentioned in string, and if found, returns that name.
-
.force_array(arg)
Wraps object in an Array if it is not an Array already.
-
.matches?(target, list, default = true)
Checks if any item in
list
matchestarget
-
.matches_date?(target, list, default = true)
Checks if any item in
list
matches the date part oftarget
-
.matches_time?(target, list, default = true)
Checks if any item in
list
matches the time part oftarget
-
.virtual_dates(list, default_list = [] of Crystime::VirtualTimeOrTime)
Replaces any values of 'true' with a list of VTs.
Class Method Detail
Checks if rule matches value, i.e. if value satisfies rule. Matching rules:
- Nil matches all it is compared with
- Number matches that number
- Block matches if it returns true when executed
- Enumerable (including Range) matches if rule.includes?(value) is true XXX throw Undeterminable if one asks for day match on date with no year, so days_in_month can't be calcd. Fold is the starting value for negative numbers. You set it to days_in_month + 1. (E.g. if you want to wrap around 31st, you pass 32 as fold value.) "DUE", "DATE"
Compares all types of accepted values for T and/or VT against each other.
Scans for day of week name mentioned in string, and if found, returns that name.
Scans for month name mentioned in string, and if found, returns that name.
Checks if any item in list
matches the date part of target
Checks if any item in list
matches the time part of target
Replaces any values of 'true' with a list of VTs. By default, the list is emtpy.