关闭。这个问题是opinion-based .它目前不接受答案。
想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题.
11 个月前关闭。
Improve this question
我想为我的项目找到一个 ruby gem,以处理符合以下要求的重复事件:
我找到了两个相关的候选人:
你能推荐一颗 gem 并描述一下它的正面和负面体验吗?
也许您也可以添加一些我没有提到的相关标准/要求。
附言用 1,5K+ 添加 recurring_events 标签的人。谢谢
最佳答案
我最终使用了 Ice_Cube出于以下原因:
这些在我的标准中并没有被它满足:
这个没有验证:
在 Rails 中从用户输入创建 Ice_Cube::Schedule 不是很方便,但可行:
class EntryForm < FormModel
include IceCube
class_eval &ValidatesTimelinessSupport[{:start_date => :datetime}]
Units = [Day = 'day', Week = 'week']
Intervals = %w[0 1 2 3 4 5 6 7 8 9]
Week_Days = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
Days_With_Letters = Week_Days.zip(%w[S M T W T F S])
attr_accessible_accessors :interval, :unit, :start_date
attr_accessible_accessors *Week_Days
def_delegators :@model, :display_title, :schedule_yaml, :schedule_yaml=
validates_date :start_date, :allow_blank => true
validates_inclusion_of :unit, :in => Units
validates_inclusion_of :interval, :in => Intervals
validates_inclusion_of :complete, :in => %w[0 1], :allow_blank => true
Week_Days.each { |day| validates_inclusion_of day, :in => %w[0 1], :allow_blank => true }
before_edit {
if not schedule_yaml.blank? and hash = YAML::load(schedule_yaml)
schedule = Schedule.from_hash(hash)
end
if schedule and rule = schedule.rrules.first
@start_date = schedule.start_date
rule_hash = rule.to_hash
@interval = rule_hash[:interval]
case rule
when DailyRule
@unit = Day
when WeeklyRule
@unit = Week
rule_hash[:validations][:day].try :each do |day_index|
send "#{Week_Days[day_index]}=", 1
end
end
else
@start_date = Date.today
@interval = 1
@unit = Day
end
}
before_save {
sd = @start_date.blank? ?
Date.today.to_all_day :
@start_date.parse_date_in_timezone
i = @interval.to_i
schedule = Schedule.new(sd)
rule = case @unit
when Day
Rule.daily i
when Week
Rule.weekly(i).day(
*Week_Days.
select { |day| send(day).to_i == 1 } )
end
schedule.add_recurrence_rule(rule)
self.schedule_yaml = schedule.to_yaml
end
}
end
关于ruby-on-rails - Ruby:使用 Gems 处理重复性日历事件的经验?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301283/