Module: Montrose::Chainable

Included in:
Montrose, Recurrence
Defined in:
lib/montrose/chainable.rb

Instance Method Summary collapse

Instance Method Details

#at(time) ⇒ Montrose::Recurrence

Create a recurrence at given time

Examples:

Montrose.daily.at("12pm")
Montrose.daily.at("9:37am")

Parameters:

  • time (String, Time)

    represents time of day

Returns:



228
229
230
# File 'lib/montrose/chainable.rb', line 228

def at(time)
  merge(at: time)
end

#between(date_range) ⇒ Montrose::Recurrence

Create a recurrence occurring between the start and end of a given date range; :between is shorthand for separate :starts and :until options. When used with explicit :start and/or :until options, those will take precedence.

Examples:

Montrose.weekly.between(Date.today..Date.new(2016, 3, 15))

Parameters:

  • date_range (Range<Date>)

Returns:



169
170
171
# File 'lib/montrose/chainable.rb', line 169

def between(date_range)
  merge(between: date_range)
end

#branch(options) ⇒ Object



372
373
374
# File 'lib/montrose/chainable.rb', line 372

def branch(options)
  Montrose::Recurrence.new(options)
end

#covering(date_range) ⇒ Montrose::Recurrence

Create a recurrence which will only emit values within the date range, also called “masking.”

Examples:

Montrose.weekly.covering(Date.tomorrow..Date.new(2016, 3, 15))

Parameters:

  • date_range (Range<Date>)

Returns:



183
184
185
# File 'lib/montrose/chainable.rb', line 183

def covering(date_range)
  merge(covering: date_range)
end

#daily(options = {}) ⇒ Montrose::Recurrence

Create a daily recurrence.

Examples:

Montrose.daily
Montrose.daily(interval: 2) #=> every 2 days
Montrose.daily(starts: 3.days.from_now)
Montrose.daily(until: 10.days.from_now)
Montrose.daily(total: 5)
Montrose.daily(except: Date.tomorrow)

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



76
77
78
# File 'lib/montrose/chainable.rb', line 76

def daily(options = {})
  branch options.merge(every: :day)
end

#day_of_month(days, *extras) ⇒ Montrose::Recurrence Also known as: mday

Create a recurrence for given days of month

Examples:

Montrose.daily.day_of_month(1, -1)
Montrose.daily.day_of_month([1, -1])
Montrose.daily.day_of_month(2..8)

Parameters:

  • days (Fixnum)

    days of month, e.g. 1, 2, -1, …

Returns:



257
258
259
# File 'lib/montrose/chainable.rb', line 257

def day_of_month(days, *extras)
  merge(mday: days.array_concat(extras))
end

#day_of_week(weekdays, *extras) ⇒ Montrose::Recurrence Also known as: day

Create a recurrence for given days of week

Examples:

Montrose.daily.day_of_week(:saturday)
Montrose.daily.day_of_week(:monday, :tuesday)
Montrose.daily.day_of_week(2..5)

Parameters:

  • weekdays (Symbol)

    days of week, e.g. :sunday, :monday, …

Returns:



273
274
275
# File 'lib/montrose/chainable.rb', line 273

def day_of_week(weekdays, *extras)
  merge(day: weekdays.array_concat(extras))
end

#day_of_year(days, *extras) ⇒ Montrose::Recurrence Also known as: yday

Create a recurrence for given days of year

Examples:

Montrose.daily.day_of_year(1, 10, 100)
Montrose.daily.day_of_year([1, 10, 100])
Montrose.daily.day_of_year(20..50)

Parameters:

  • days (Fixnum, Range, Array<Integer>)

    days of year, e.g., 1, 10, 100, …

Returns:



289
290
291
# File 'lib/montrose/chainable.rb', line 289

def day_of_year(days, *extras)
  merge(yday: days.array_concat(extras))
end

#default_optionsObject



377
378
379
# File 'lib/montrose/chainable.rb', line 377

def default_options
  @default_options ||= Montrose::Options.new
end

#during(time_of_day, *extras) ⇒ Montrose::Recurrence

Create a recurrence occurring within a time-of-day range or ranges. Given time ranges will parse as times-of-day and ignore given dates.

Examples:

Montrose.every(20.minutes).during("9am-5pm")
Montrose.every(20.minutes).during(time.change(hour: 9)..time.change(hour: 5))
Montrose.every(20.minutes).during([9, 0, 0], [17, 0, 0])
Montrose.every(20.minutes).during("9am-12pm", "1pm-5pm")

Parameters:

  • time-of-day (Range<Time>, String, Array<Array>)

    range(s)

Returns:



200
201
202
# File 'lib/montrose/chainable.rb', line 200

def during(time_of_day, *extras)
  merge(during: time_of_day.array_concat(extras))
end

#every(frequency, options = {}) ⇒ Montrose::Recurrence

Create a recurrence from the given frequency

Examples:

Montrose.every(:hour)
Montrose.every(:hour, interval: 2)
Montrose.every(3.days, starts: 2.days.from_now)
Montrose.every(1.year, until: 10.days.from_now)

Parameters:

  • frequency (Symbol, String, Numeric)

    the recurrence frequency

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



22
23
24
# File 'lib/montrose/chainable.rb', line 22

def every(frequency, options = {})
  branch options.merge(every: frequency)
end

#except(date) ⇒ Montrose::Recurrence

Create a recurrence with dates except dates given

Examples:

Montrose.daily.except("2016-03-01")
Montrose.daily.except(Date.today)

Parameters:

  • date (String, Date)

    represents date

Returns:



242
243
244
# File 'lib/montrose/chainable.rb', line 242

def except(date)
  merge(except: date)
end

#hour_of_day(hours, *extras) ⇒ Montrose::Recurrence Also known as: hour

Create a recurrence for given hours of day

Examples:

Montrose.hourly.hour_of_day(9)
Montrose.hourly.hour_of_day(15)
Montrose.hourly.hour_of_day(6..10)

Parameters:

  • hours (Fixnum, Range, Array<Integer>)

    hours of day, e.g. 1, 10, 100, …

Returns:



305
306
307
# File 'lib/montrose/chainable.rb', line 305

def hour_of_day(hours, *extras)
  merge(hour: hours.array_concat(extras))
end

#hourly(options = {}) ⇒ Montrose::Recurrence

Create a hourly recurrence.

Examples:

Montrose.hourly
Montrose.hourly(interval: 2) #=> every 2 hours
Montrose.hourly(starts: 3.days.from_now)
Montrose.hourly(until: 10.days.from_now)
Montrose.hourly(total: 5)
Montrose.hourly(except: Date.tomorrow)

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



58
59
60
# File 'lib/montrose/chainable.rb', line 58

def hourly(options = {})
  branch options.merge(every: :hour)
end

#merge(other = {}) ⇒ Montrose::Recurrence

Create a new recurrence combining options of self and other. The value of entries with duplicate keys will be those of other

Examples:

Montrose.daily.total(10)

Parameters:

Returns:



367
368
369
# File 'lib/montrose/chainable.rb', line 367

def merge(other = {})
  branch default_options.merge(other)
end

#minutely(options = {}) ⇒ Montrose::Recurrence

Create a minutely recurrence.

Examples:

Montrose.minutely
Montrose.minutely(interval: 2) #=> every 2 minutes
Montrose.minutely(starts: 3.days.from_now)
Montrose.minutely(until: 10.days.from_now)
Montrose.minutely(total: 5)
Montrose.minutely(except: Date.tomorrow)

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



40
41
42
# File 'lib/montrose/chainable.rb', line 40

def minutely(options = {})
  branch options.merge(every: :minute)
end

#month_of_year(months, *extras) ⇒ Montrose::Recurrence Also known as: month

Create a recurrence for given months of year

Examples:

Montrose.monthly.month_of_year(9)
Montrose.monthly.month_of_year([2, 5])
Montrose.monthly.month_of_year(2..5)

Parameters:

  • months (Fixnum, Symbol)

    months of year, e.g., :january, :april, …

Returns:



321
322
323
# File 'lib/montrose/chainable.rb', line 321

def month_of_year(months, *extras)
  merge(month: months.array_concat(extras))
end

#monthly(options = {}) ⇒ Montrose::Recurrence

Create a monthly recurrence.

Examples:

Montrose.monthly(mday: [2, 15]) # 2nd and 15th of the month
Montrose.monthly(mday: -3) # third-to-last day of the month
Montrose.monthly(mday: 10..15) # 10th through the 15th day of the month

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



108
109
110
# File 'lib/montrose/chainable.rb', line 108

def monthly(options = {})
  branch options.merge(every: :month)
end

#on(day) ⇒ Montrose::Recurrence

Create a recurrence through :on option

Examples:

Montrose.weekly.on(:friday)
Montrose.monthly.on(friday: 13)

Parameters:

  • day (Hash, Symbol)

    weekday or day of month as hash, e.g. { friday: 13 }

Returns:



214
215
216
# File 'lib/montrose/chainable.rb', line 214

def on(day)
  merge(on: day)
end

#starts(starts_at) ⇒ Montrose::Recurrence Also known as: starting

Create a recurrence starting at given timestamp.

Examples:

Montrose.daily.starting(Date.tomorrow)

Parameters:

  • starts_at (Time, Date)

    start time of recurrence

Returns:



138
139
140
# File 'lib/montrose/chainable.rb', line 138

def starts(starts_at)
  merge(starts: starts_at)
end

#total(total) ⇒ Montrose::Recurrence Also known as: repeat

Create a recurrence that ends after given number of occurrences

Examples:

Montrose.daily.total(10)

Parameters:

  • total (Fixnum)

    repeat count

Returns:



351
352
353
# File 'lib/montrose/chainable.rb', line 351

def total(total)
  merge(total: total)
end

#until(ends_at) ⇒ Montrose::Recurrence Also known as: ending

Create a recurrence ending at given timestamp.

Examples:

Montrose.daily.ending(1.year.from_now)

Parameters:

  • ends_at (Time, Date)

    end time of recurrence

Returns:



152
153
154
# File 'lib/montrose/chainable.rb', line 152

def until(ends_at)
  merge(until: ends_at)
end

#week_of_year(weeks, *extras) ⇒ Montrose::Recurrence

Create a recurrence for given weeks of year

Examples:

Montrose.weekly.week_of_year(9)
Montrose.weekly.week_of_year([2, 5])
Montrose.weekly.week_of_year(2..5)

Parameters:

  • weeks (Fixnum)

    weeks of year, e.g., 1, 20, 50

Returns:



337
338
339
# File 'lib/montrose/chainable.rb', line 337

def week_of_year(weeks, *extras)
  merge(week: weeks.array_concat(extras))
end

#weekly(options = {}) ⇒ Montrose::Recurrence

Create a weekly recurrence.

Examples:

Montrose.weekly(on: 5) #=> 0 = sunday, 1 = monday, ...
Montrose.weekly(on: :saturday)
Montrose.weekly(on: [sunday, :saturday])
Montrose.weekly(on: :saturday, interval: 2)
Montrose.weekly(on: :saturday, total: 5)

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



93
94
95
# File 'lib/montrose/chainable.rb', line 93

def weekly(options = {})
  branch options.merge(every: :week)
end

#yearly(options = {}) ⇒ Montrose::Recurrence

Create a yearly recurrence.

Examples:

Montrose.yearly(on: [7, 14]) #=> every Jul 14
Montrose.yearly(on: [7, 14], interval: 2) #=> every 2 years on Jul 14
Montrose.yearly(on: [:jan, 14], interval: 2)
Montrose.yearly(on: [:january, 14], interval: 2)
Montrose.yearly(on: [:january, 14], total: 5)

Parameters:

  • options (Hash) (defaults to: {})

    additional recurrence options

Returns:



125
126
127
# File 'lib/montrose/chainable.rb', line 125

def yearly(options = {})
  branch options.merge(every: :year)
end