0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

KOIL CSCAdvent Calendar 2016

Day 8

Railsのice_cubeを触ってみる

Last updated at Posted at 2016-12-07

ice_cubeを利用した時の内容を記述します。

インスタンスを作成する。

schedule = IceCube::Schedule.new(Time.local(2010, 7, 1))

ベーシックな方法

room = Room.new()
room.schedule = IceCube::Schedule.new(Date.today, duration: 1.day)
room.schedule.add_recurrence_rule IceCube::Rule.weekly.day(:friday,:saturday,:sunday)
room.save!

もっともベーシックな記述方法です。
指定した期間内で、対象としたい曜日を追加します。

checkin/out

チェックイン/アウトする日付を指定します。

check_in_ok = Date.today.next_week + 4.days
check_out_ok = check_in_ok + 2.days

u = User.find(1)
u.book! room, time_start: check_in_ok, time_end: check_out_ok

r = Room.new()
r.schedule = IceCube::Schedule.new(Time.now, duration: 10.hours)
r.schedule.add_recurrence_rule IceCube::Rule.weekly.day(:monday).hour_of_day(8)
r.save!

予約成功と失敗事例

booking成功時間と失敗時間を試します。

from_ok = Date.today.next_week + 9.hours
to_ok = from_ok + 2.hours
from_wrong = Date.today.next_week + 1.day + 9.hours
to_wrong = from_wrong + 2.hours

u = User.find(2)
u.book! r, time_start: from_ok, time_end: to_ok
u.book! r, time_start: from_wrong, time_end: to_wrong

room = Room.new()
room.schedule = IceCube::Schedule.new(Time.now, duration: 10.hours)
room.schedule.add_recurrence_rule IceCube::Rule.weekly.day(:monday).hour_of_day(8)
room.save!
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?