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:


194
195
196
# File 'lib/montrose/chainable.rb', line 194

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

#between(date_range) ⇒ Montrose::Recurrence

Create a recurrence occurring during date range.

Examples:

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

Parameters:

  • date_range (Range<Date>)

Returns:


166
167
168
# File 'lib/montrose/chainable.rb', line 166

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

#branch(options) ⇒ Object


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

def branch(options)
  Montrose::Recurrence.new(options)
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:


223
224
225
# File 'lib/montrose/chainable.rb', line 223

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:


239
240
241
# File 'lib/montrose/chainable.rb', line 239

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:


255
256
257
# File 'lib/montrose/chainable.rb', line 255

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

#default_optionsObject


343
344
345
# File 'lib/montrose/chainable.rb', line 343

def default_options
  @default_options ||= Montrose::Options.new
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:


208
209
210
# File 'lib/montrose/chainable.rb', line 208

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:


271
272
273
# File 'lib/montrose/chainable.rb', line 271

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:


333
334
335
# File 'lib/montrose/chainable.rb', line 333

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:


287
288
289
# File 'lib/montrose/chainable.rb', line 287

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:


180
181
182
# File 'lib/montrose/chainable.rb', line 180

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:


317
318
319
# File 'lib/montrose/chainable.rb', line 317

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:


303
304
305
# File 'lib/montrose/chainable.rb', line 303

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