ice_cube icon indicating copy to clipboard operation
ice_cube copied to clipboard

Rule Groups

Open avit opened this issue 13 years ago • 2 comments

As a follow up to #79, I'm using this pattern successfully in my schedule_attributes:

schedule.rrules = [
  Rule.daily.month_of_year(11, 12, 1, 2, 3)
]
schedule.exrules = [
  Rule.daily.month_of_year(11).day_of_month(*1..14),
  Rule.daily.month_of_year(3).day_of_month(*16..31),
]
# effectively: Daily from November 15 to March 15 every year

The only problem is that because this pattern is represented by 3 rules, I need to treat them as one logical "rule group" to extract the "yearly start day" and "yearly end day" for the UI, and this makes it hard to have any other rules within the same schedule without getting them mixed together when going back/forth from the UI.

I envision having something like "groups" for rules, or maybe just give each rule a "tag" so I can identify rules that belong together. Any thoughts on this idea?

avit avatar Dec 08 '12 02:12 avit

I like this idea - do you think a workable alternative (a bit less lightweight) would be to just have the ability to set a meta string on each rule? So if you wanted a rule to be able to be part of multiple rulesets, you'd serialize something into this value - looking for any feedback you have on this - but in general sounds like a solid idea

seejohnrun avatar Dec 16 '12 23:12 seejohnrun

Yes, a lightweight meta "tag" or such is pretty much what I was thinking of, too.

I'm not sure why you'd need to have a rule in more than one ruleset, it seems like that just adds more complexity. Would a simple string key be sufficient? Or, if it's matched using include? then it could be either a string or array...

Possibly:

# group1
schedule.add_reccurrence_rule(
  Rule.daily.month_of_year(1, 2).meta('group1')
)
schedule.add_exception_rule(
  Rule.daily.month_of_year(1).day_of_month(*1..15).meta('group1')
)

# group2
schedule.add_reccurrence_rule(
  Rule.daily.month_of_year(6,7).meta('group2')
)
schedule.add_exception_rule(
  Rule.daily.month_of_year(6).day_of_month(*1..15).meta('group2')
)

schedule.rulesets
# {
#  "group1" => {:rrules => [...], :exrules => [...], :rtimes =>[], :extimes => []},
#  "group2" => {:rrules => [...], :exrules => [...], :rtimes =>[], :extimes => []}
# }
  1. A chainable meta method for setting the tag: this would return "self", any thoughts on a better interface for reading the meta attribute?
  2. A rulesets method for getting partitioned rules: I'm thinking the default key would just be be nil for rules with no meta?

avit avatar Dec 18 '12 09:12 avit