Module: Recurify::RuleAnalysis
- Included in:
- Rule
- Defined in:
- lib/recurify/rule_analysis.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#denormalized? ⇒ Boolean
Returns
true
ifself
is denormalized. -
#ends_after?(lower) ⇒ Boolean
Returns
true
ifself
ends after or onlower
. -
#ends_before?(upper) ⇒ Boolean
Returns
true
ifself
ends before or onupper
. -
#ends_between?(lower: nil, upper: nil) ⇒ Boolean
Returns
true
ifself
ends afterlower
and ends beforeupper
(including boundaries). -
#finite? ⇒ Boolean
Returns
true
ifself
is finite. -
#infinite? ⇒ Boolean
Returns
true
ifself
is infinite. -
#normalized? ⇒ Boolean
Returns
true
ifself
is normalized. -
#one? ⇒ Boolean
Returns
true
if and only ifself
evaluates to a single occurrence. -
#overlaps?(lower: nil, upper: nil) ⇒ Boolean
Returns
true
ifself
starts and/or ends betweenlower
andupper
(including boundaries). -
#starts_after?(lower) ⇒ Boolean
Returns
true
ifself
starts after or onlower
. -
#starts_before?(upper) ⇒ Boolean
Returns
true
ifself
starts before or onupper
. -
#starts_between?(lower: nil, upper: nil) ⇒ Boolean
Returns
true
ifself
starts afterlower
and starts beforeupper
(including boundaries).
Instance Method Details
#denormalized? ⇒ Boolean
Returns true
if self
is denormalized. By definition, a Rule
is denormalized if and only if it is not normalized.
19 20 21 |
# File 'lib/recurify/rule_analysis.rb', line 19 def denormalized? !normalized? end |
#ends_after?(lower) ⇒ Boolean
Returns true
if self
ends after or on lower
. If lower == nil, it is interpreted as “negative infinity”. In that case, #ends_after?
always returns true
.
112 113 114 115 116 117 118 119 120 |
# File 'lib/recurify/rule_analysis.rb', line 112 def ends_after?(lower) false || # Case (1): 'infinite' >= [anything] ==> true normalized_ends_on.nil? || # Case (2): 'finite' >= 'infinite' ==> true lower.nil? || # Case (3): 'finite' >= 'finite' ==> depends on actual comparison normalized_ends_on >= lower.to_date end |
#ends_before?(upper) ⇒ Boolean
Returns true
if self
ends before or on upper
. If upper == nil, it is interpreted as “positive infinity”. In that case, #ends_before?
always returns true
.
97 98 99 100 101 102 103 |
# File 'lib/recurify/rule_analysis.rb', line 97 def ends_before?(upper) false || # Case (1): [anything] <= 'infinite' ==> true upper.nil? || # Case (2): 'finite' <= 'finite' ==> depends on actual comparison !normalized_ends_on.nil? && normalized_ends_on <= upper.to_date end |
#ends_between?(lower: nil, upper: nil) ⇒ Boolean
Returns true
if self
ends after lower
and ends before upper
(including boundaries).
132 133 134 |
# File 'lib/recurify/rule_analysis.rb', line 132 def ends_between?(lower: nil, upper: nil) ends_after?(lower) && ends_before?(upper) end |
#finite? ⇒ Boolean
Returns true
if self
is finite. By definition, a Rule
is finite if and only if it is not infinite.
29 30 31 32 33 |
# File 'lib/recurify/rule_analysis.rb', line 29 def finite? # @todo Checking of the #count is not needed anymore, once #normalize # supports minifying of #ends_on. !count.nil? || !normalized_ends_on.nil? end |
#infinite? ⇒ Boolean
Returns true
if self
is infinite. By definition, a Rule
is infinite if and only if it is not finite.
41 42 43 |
# File 'lib/recurify/rule_analysis.rb', line 41 def infinite? !finite? end |
#normalized? ⇒ Boolean
Returns true
if self
is normalized. By definition, a Rule
is normalized if and only if it is not denormalized.
9 10 11 |
# File 'lib/recurify/rule_analysis.rb', line 9 def normalized? attributes == normalized_attributes end |
#one? ⇒ Boolean
Returns true
if and only if self
evaluates to a single occurrence.
48 49 50 |
# File 'lib/recurify/rule_analysis.rb', line 48 def one? starts_on == normalized_ends_on end |
#overlaps?(lower: nil, upper: nil) ⇒ Boolean
Returns true
if self
starts and/or ends between lower
and upper
(including boundaries).
146 147 148 149 150 151 152 |
# File 'lib/recurify/rule_analysis.rb', line 146 def overlaps?(lower: nil, upper: nil) false || # Case (1): +lower+ <= starts_on <= +upper+ ==> true starts_between?(lower: lower, upper: upper) || # Case (2): +lower+ <= normalized_ends_on <= +upper+ ==> true ends_between?(lower: lower, upper: upper) end |
#starts_after?(lower) ⇒ Boolean
Returns true
if self
starts after or on lower
. If lower == nil, it is interpreted as “negative infinity”. In that case, #starts_after?
always returns true
, because all Rule
objects must have a finite #starts_on
attribute.
72 73 74 |
# File 'lib/recurify/rule_analysis.rb', line 72 def starts_after?(lower) lower.nil? || starts_on >= lower.to_date end |
#starts_before?(upper) ⇒ Boolean
Returns true
if self
starts before or on upper
. If upper == nil, it is interpreted as “positive infinity”. In that case, #starts_before?
always returns true
, because all Rule
objects must have a finite #starts_on
attribute.
60 61 62 |
# File 'lib/recurify/rule_analysis.rb', line 60 def starts_before?(upper) upper.nil? || starts_on <= upper.to_date end |
#starts_between?(lower: nil, upper: nil) ⇒ Boolean
Returns true
if self
starts after lower
and starts before upper
(including boundaries).
86 87 88 |
# File 'lib/recurify/rule_analysis.rb', line 86 def starts_between?(lower: nil, upper: nil) starts_after?(lower) && starts_before?(upper) end |