Module: MerchCalendar::Util

Included in:
MerchCalendar
Defined in:
lib/merch_calendar/util.rb

Overview

Utility methods for the merch calendar

Instance Method Summary collapse

Instance Method Details

#end_of_month(year, month_param) ⇒ Date

The end date of the month

Parameters:

  • year (Fixnum)

    the merch year

  • month_param (Hash)

    month hash

Returns:

  • (Date)

See Also:


35
36
37
38
# File 'lib/merch_calendar/util.rb', line 35

def end_of_month(year, month_param)
  merch_month = get_merch_month_param(month_param)
  date_calc.end_of_month(year, merch_month)
end

#end_of_quarter(year, quarter) ⇒ Date

The end date of the quarter

Parameters:

  • year (Fixnum)

    the merch year

  • quarter (Fixnum)

    the quarter

Returns:

  • (Date)

    the ending date of the specified quarter


75
76
77
# File 'lib/merch_calendar/util.rb', line 75

def end_of_quarter(year, quarter)
  date_calc.end_of_quarter(year, quarter)
end

#end_of_year(year) ⇒ Date

The end date of the year

Parameters:

  • year (Fixnum)

    the merch year

Returns:

  • (Date)

    the ending date of the specified year


54
55
56
# File 'lib/merch_calendar/util.rb', line 54

def end_of_year(year)
  date_calc.end_of_year(year)
end

#julian_to_merch(month) ⇒ Fixnum

Converts a julian month to a merch month

Parameters:

  • month (Fixnum)

    the julian month to convert

Returns:

  • (Fixnum)

    the merch month


103
104
105
# File 'lib/merch_calendar/util.rb', line 103

def julian_to_merch(month)
  date_calc.julian_to_merch(month)
end

#merch_to_julian(month) ⇒ Fixnum

Converts a merch month to the correct julian month

Parameters:

  • month (Fixnum)

    the merch month to convert

Returns:

  • (Fixnum)

    the julian month


95
96
97
# File 'lib/merch_calendar/util.rb', line 95

def merch_to_julian(month)
  date_calc.merch_to_julian(month)
end

#start_of_month(year, month_param) ⇒ Date

The start date of the month

Examples:

# The following are all equivalent, and refer to May 2015
MerchCalendar.start_of_month(2015, 5)
MerchCalendar.start_of_month(2015, month: 5)
MerchCalendar.start_of_month(2015, julian_month: 5)
MerchCalendar.start_of_month(2015, merch_month: 4)

Parameters:

  • year (Fixnum)

    the merch year

  • month_param (Fixnum, Hash)

    an integer specifying the julian month. This can also be a named hash

Options Hash (month_param):

  • :month (Fixnum)

    the julian month

  • :julian_month (Fixnum)

    the julian month

  • :merch_month (Fixnum)

    the MERCH month

Returns:

  • (Date)

    the starting date of the specified month


22
23
24
25
# File 'lib/merch_calendar/util.rb', line 22

def start_of_month(year, month_param)
  merch_month = get_merch_month_param(month_param)
  date_calc.start_of_month(year, merch_month)
end

#start_of_quarter(year, quarter) ⇒ Date

The start date of the quarter

Parameters:

  • year (Fixnum)

    the merch year

  • quarter (Fixnum)

    the quarter

Returns:

  • (Date)

    the starting date of the specified quarter


65
66
67
# File 'lib/merch_calendar/util.rb', line 65

def start_of_quarter(year, quarter)
  date_calc.start_of_quarter(year, quarter)
end

#start_of_year(year) ⇒ Date

The start date of the year

Parameters:

  • year (Fixnum)

    the merch year

Returns:

  • (Date)

    the starting date of the specified year


45
46
47
# File 'lib/merch_calendar/util.rb', line 45

def start_of_year(year)
  date_calc.start_of_year(year)
end

#weeks_for_month(year, month_param) ⇒ Array<MerchWeek>

An array of merch weeks in a given month

Parameters:

  • year (Fixnum)

    the merch year

  • month_param (Hash)

    month hash

Returns:

See Also:


115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/merch_calendar/util.rb', line 115

def weeks_for_month(year, month_param)
  merch_month = get_merch_month_param(month_param)

  start_date = date_calc.start_of_month(year, merch_month)

  weeks = (date_calc.end_of_month(year, merch_month) - start_date + 1) / 7

  (1..weeks).map do |week_num|
    week_start = start_date + ((week_num - 1) * 7)
    week_end = week_start + 6
    MerchWeek.new(week_start, { start_of_week: week_start, end_of_week: week_end, week: week_num })
  end
end

#weeks_in_year(year) ⇒ Fixnum

Returns the number of weeks in a given merch year

Parameters:

  • year (Fixnum)

    the merch year

Returns:

  • (Fixnum)

    number of weeks


85
86
87
# File 'lib/merch_calendar/util.rb', line 85

def weeks_in_year(year)
  date_calc.weeks_in_year(year)
end