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.cr

Constant 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

Class Method Detail

def self.check(rule, value, fold = nil) #

Checks if rule matches value, i.e. if value satisfies rule. Matching rules:

  1. Nil matches all it is compared with
  2. Number matches that number
  3. Block matches if it returns true when executed
  4. 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"

[View source]
def self.compare(a : Enumerable(Int), b : Enumerable(Int)) #

Compares all types of accepted values for T and/or VT against each other.


[View source]
def self.compare(a : Proc(Int32, Bool), b : Int) #

[View source]
def self.compare(a : Int, b : Proc(Int32, Bool)) #

[View source]
def self.compare(a : Enumerable(Int), b : Int) #

[View source]
def self.compare(a : Nil, b) #

[View source]
def self.compare(a, b : Nil) #

[View source]
def self.compare(a : Int, b : Enumerable(Int)) #

[View source]
def self.compare(a, b) #

[View source]
def self.find_day_of_week(str) #

Scans for day of week name mentioned in string, and if found, returns that name.


[View source]
def self.find_month(str) #

Scans for month name mentioned in string, and if found, returns that name.


[View source]
def self.force_array(arg) #

Wraps object in an Array if it is not an Array already.


[View source]
def self.matches?(target, list, default = true) #

Checks if any item in list matches target


[View source]
def self.matches_date?(target, list, default = true) #

Checks if any item in list matches the date part of target


[View source]
def self.matches_time?(target, list, default = true) #

Checks if any item in list matches the time part of target


[View source]
def self.virtual_dates(list, default_list = [] of Crystime::VirtualTimeOrTime) #

Replaces any values of 'true' with a list of VTs. By default, the list is emtpy.


[View source]