Class: Nickel::Occurrence

Inherits:
Struct
  • Object
show all
Defined in:
lib/nickel/occurrence.rb

Overview

Some notes about this class, type can take the following values: :single, :daily, :weekly, :daymonthly, :datemonthly,

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Occurrence

Returns a new instance of Occurrence.



6
7
8
# File 'lib/nickel/occurrence.rb', line 6

def initialize(h)
  h.each { |k, v| send("#{k}=", v) }
end

Instance Attribute Details

#date_of_monthObject

Returns the value of attribute date_of_month

Returns:

  • (Object)

    the current value of date_of_month



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def date_of_month
  @date_of_month
end

#day_of_weekObject

Returns the value of attribute day_of_week

Returns:

  • (Object)

    the current value of day_of_week



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def day_of_week
  @day_of_week
end

#end_dateObject

Returns the value of attribute end_date

Returns:

  • (Object)

    the current value of end_date



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def end_date
  @end_date
end

#end_timeObject

Returns the value of attribute end_time

Returns:

  • (Object)

    the current value of end_time



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def end_time
  @end_time
end

#intervalObject

Returns the value of attribute interval

Returns:

  • (Object)

    the current value of interval



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def interval
  @interval
end

#start_dateObject

Returns the value of attribute start_date

Returns:

  • (Object)

    the current value of start_date



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def start_date
  @start_date
end

#start_timeObject

Returns the value of attribute start_time

Returns:

  • (Object)

    the current value of start_time



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def start_time
  @start_time
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def type
  @type
end

#week_of_monthObject

Returns the value of attribute week_of_month

Returns:

  • (Object)

    the current value of week_of_month



4
5
6
# File 'lib/nickel/occurrence.rb', line 4

def week_of_month
  @week_of_month
end

Instance Method Details

#finalize(cur_date) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/nickel/occurrence.rb', line 14

def finalize(cur_date)
  cur_date = start_date unless start_date.nil?
  case type
  when :daily then finalize_daily(cur_date)
  when :weekly then finalize_weekly(cur_date)
  when :datemonthly then finalize_datemonthly(cur_date)
  when :daymonthly then finalize_daymonthly(cur_date)
  end
end

#inspectObject



10
11
12
# File 'lib/nickel/occurrence.rb', line 10

def inspect
  '#<Occurrence ' + members.select { |m| self[m] }.map { |m| %(#{m}: #{self[m]}) }.join(', ') + '>'
end