Class: Recurify::Rule
- Inherits:
-
Object
- Object
- Recurify::Rule
- Includes:
- RuleAnalysis, RuleTranslation, RuleValidation
- Defined in:
- lib/recurify/rule.rb
Overview
Represents a Recurrence Rule. Note that Rule objects are immutable once they are instantiated (i.e. they are value objects).
Constant Summary collapse
- BASE_FREQUENCIES =
%w(daily monthly).freeze
- SUGAR_FREQUENCIES =
%w(weekly quarterly yearly).freeze
- SUPPORTED_FREQUENCIES =
(BASE_FREQUENCIES + SUGAR_FREQUENCIES).freeze
Constants included from RuleTranslation
Recurify::RuleTranslation::DENORMALIZATION_MATRIX, Recurify::RuleTranslation::NORMALIZATION_MATRIX
Constants included from RuleValidation
Recurify::RuleValidation::MIN_COUNT, Recurify::RuleValidation::MIN_INTERVAL
Instance Attribute Summary collapse
- #count ⇒ Fixnum? readonly
- #ends_on ⇒ Date? readonly
- #frequency ⇒ String readonly
- #interval ⇒ Fixnum readonly
- #starts_on ⇒ Date readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Tests for equality with
other. -
#attributes ⇒ Hash<Symbol,Object>
Convert
selfto aHash, representing the sameRule. -
#initialize(attributes = {}) ⇒ Rule
constructor
Returns a new instance of
Rule. -
#substitute(substitutions = {}) ⇒ Rule
Creates a new instance of
Rulewith substituted attributes.
Methods included from RuleTranslation
#denormalize, #denormalized_count, #denormalized_ends_on, #denormalized_frequency, #denormalized_interval, #normalize, #normalized_count, #normalized_ends_on, #normalized_frequency, #normalized_interval
Methods included from RuleAnalysis
#denormalized?, #ends_after?, #ends_before?, #ends_between?, #finite?, #infinite?, #normalized?, #overlaps?, #starts_after?, #starts_before?, #starts_between?
Constructor Details
#initialize(attributes = {}) ⇒ Rule
Returns a new instance of Rule.
52 53 54 55 |
# File 'lib/recurify/rule.rb', line 52 def initialize(attributes = {}) self.attributes = self.class.default_attributes.merge(attributes) validate! end |
Instance Attribute Details
#count ⇒ Fixnum? (readonly)
27 28 29 |
# File 'lib/recurify/rule.rb', line 27 def count @count end |
#ends_on ⇒ Date? (readonly)
35 36 37 |
# File 'lib/recurify/rule.rb', line 35 def ends_on @ends_on end |
#frequency ⇒ String (readonly)
23 24 25 |
# File 'lib/recurify/rule.rb', line 23 def frequency @frequency end |
#interval ⇒ Fixnum (readonly)
23 24 25 |
# File 'lib/recurify/rule.rb', line 23 def interval @interval end |
#starts_on ⇒ Date (readonly)
31 32 33 |
# File 'lib/recurify/rule.rb', line 31 def starts_on @starts_on end |
Instance Method Details
#==(other) ⇒ Boolean
Tests for equality with other.
Two Rule objects are considered to be equal, if and only if they both evaluate to the same same set of Date objects.
75 76 77 |
# File 'lib/recurify/rule.rb', line 75 def ==(other) normalize.attributes == other.normalize.attributes end |
#attributes ⇒ Hash<Symbol,Object>
Convert self to a Hash, representing the same Rule. Note, that #attributes is essentially the inverse of #initialize.
83 84 85 86 87 88 89 90 91 |
# File 'lib/recurify/rule.rb', line 83 def attributes @_attributes ||= { frequency: frequency, interval: interval, count: count, starts_on: starts_on, ends_on: ends_on } end |
#substitute(substitutions = {}) ⇒ Rule
Creates a new instance of Rule with substituted attributes. Attributes that haven’t been specified are copied from self.
64 65 66 |
# File 'lib/recurify/rule.rb', line 64 def substitute(substitutions = {}) self.class.new(attributes.merge(substitutions)) end |