Class: Month

Inherits:
Object
  • Object
show all
Extended by:
Constants
Includes:
Comparable
Defined in:
lib/Month/eqlQ.rb,
lib/Month/day.rb,
lib/Month/end.rb,
lib/Month/date.rb,
lib/Month/days.rb,
lib/Month/hash.rb,
lib/Month/last.rb,
lib/Month/next.rb,
lib/Month/plus.rb,
lib/Month/prev.rb,
lib/Month/succ.rb,
lib/Month/to_i.rb,
lib/Month/to_s.rb,
lib/Month/cdate.rb,
lib/Month/dates.rb,
lib/Month/minus.rb,
lib/Month/prior.rb,
lib/Month/start.rb,
lib/Month/cdates.rb,
lib/Month/finish.rb,
lib/Month/to_num.rb,
lib/Month/VERSION.rb,
lib/Month/self.of.rb,
lib/Month/to_date.rb,
lib/Month/to_long.rb,
lib/Month/day_long.rb,
lib/Month/each_day.rb,
lib/Month/end_date.rb,
lib/Month/previous.rb,
lib/Month/self.day.rb,
lib/Month/self.end.rb,
lib/Month/self.now.rb,
lib/Month/to_short.rb,
lib/Month/Constants.rb,
lib/Month/beginning.rb,
lib/Month/day_short.rb,
lib/Month/last_year.rb,
lib/Month/next_year.rb,
lib/Month/self.date.rb,
lib/Month/self.days.rb,
lib/Month/self.last.rb,
lib/Month/self.next.rb,
lib/Month/self.prev.rb,
lib/Month/self.succ.rb,
lib/Month/self.this.rb,
lib/Month/self.to_i.rb,
lib/Month/self.wday.rb,
lib/Month/successor.rb,
lib/Month/to_number.rb,
lib/Month/begin_date.rb,
lib/Month/initialize.rb,
lib/Month/last_month.rb,
lib/Month/next_month.rb,
lib/Month/prev_month.rb,
lib/Month/self.cdate.rb,
lib/Month/self.dates.rb,
lib/Month/self.prior.rb,
lib/Month/self.start.rb,
lib/Month/self.today.rb,
lib/Month/start_date.rb,
lib/Month/succ_month.rb,
lib/Month/_comparator.rb,
lib/Month/finish_date.rb,
lib/Month/prior_month.rb,
lib/Month/self.cdates.rb,
lib/Month/self.finish.rb,
lib/Month/self.to_num.rb,
lib/Month/day_shortest.rb,
lib/Month/end_of_month.rb,
lib/Month/self.to_long.rb,
lib/Month/days_in_month.rb,
lib/Month/self.day_long.rb,
lib/Month/self.end_date.rb,
lib/Month/self.previous.rb,
lib/Month/self.to_short.rb,
lib/Month/method_missing.rb,
lib/Month/previous_month.rb,
lib/Month/self.beginning.rb,
lib/Month/self.day_short.rb,
lib/Month/self.from_date.rb,
lib/Month/self.last_year.rb,
lib/Month/self.next_year.rb,
lib/Month/self.successor.rb,
lib/Month/self.to_number.rb,
lib/Month/start_of_month.rb,
lib/Month/finish_of_month.rb,
lib/Month/self.begin_date.rb,
lib/Month/self.last_month.rb,
lib/Month/self.next_month.rb,
lib/Month/self.prev_month.rb,
lib/Month/self.start_date.rb,
lib/Month/self.succ_month.rb,
lib/Month/successor_month.rb,
lib/Month/end_of_the_month.rb,
lib/Month/self.finish_date.rb,
lib/Month/self.prior_month.rb,
lib/Month/days_in_the_month.rb,
lib/Month/self.day_shortest.rb,
lib/Month/self.end_of_month.rb,
lib/Month/beginning_of_month.rb,
lib/Month/self.days_in_month.rb,
lib/Month/start_of_the_month.rb,
lib/Month/finish_of_the_month.rb,
lib/Month/self.method_missing.rb,
lib/Month/self.previous_month.rb,
lib/Month/self.start_of_month.rb,
lib/Month/self.finish_of_month.rb,
lib/Month/self.successor_month.rb,
lib/Month/self.end_of_the_month.rb,
lib/Month/beginning_of_the_month.rb,
lib/Month/self.days_in_the_month.rb,
lib/Month/self.beginning_of_month.rb,
lib/Month/self.start_of_the_month.rb,
lib/Month/self.finish_of_the_month.rb,
lib/Month/self.beginning_of_the_month.rb

Overview

20140606

Defined Under Namespace

Modules: Constants

Constant Summary collapse

VERSION =
'0.11.4'

Constants included from Constants

Constants::ISO_8601_WEEK_DAY_NAMES_LONG, Constants::ISO_8601_WEEK_DAY_NAMES_SHORT, Constants::ISO_8601_WEEK_DAY_NAMES_SHORTEST, Constants::ISO_8601_WEEK_DAY_NUMBERS, Constants::ISO_8601_WEEK_DAY_NUMBERS_AS_STRINGS, Constants::MONTH_DAYS, Constants::MONTH_DAY_NUMBERS, Constants::MONTH_NAMES_LONG, Constants::MONTH_NAMES_SHORT, Constants::MONTH_NUMBERS, Constants::MONTH_NUMBERS_AS_STRINGS, Constants::WEEK_DAY_NAMES_LONG, Constants::WEEK_DAY_NAMES_SHORT, Constants::WEEK_DAY_NAMES_SHORTEST, Constants::WEEK_DAY_NUMBERS, Constants::WEEK_DAY_NUMBERS_AS_STRINGS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Month

Returns a new instance of Month.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/Month/initialize.rb', line 15

def initialize(*args)
  @year, @month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  fail unless (1..12).include?(@month)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/Month/method_missing.rb', line 8

def method_missing(method_name, *args, &block)
  case method_name.to_s
  when /^((m|M)o)|((m|M)on)(day|days)*$/; Month.dates(year, month, :day => 'Monday')
  when /^((t|T)u)|((t|T)ue)(sday|sdays)*$/; Month.dates(year, month, :day => 'Tuesday')
  when /^((w|W)e)|((w|W)ed)(nesday|nesdays)*$/; Month.dates(year, month, :day => 'Wednesday')
  when /^((t|T)h)|((t|T)hu)(rsday|rsdays)*$/; Month.dates(year, month, :day => 'Thursday')
  when /^((f|F)r)|((f|F)ri)(day|days)*$/; Month.dates(year, month, :day => 'Friday')
  when /^((s|S)a)|((s|S)at)(urday|urdays)*$/; Month.dates(year, month, :day => 'Saturday')
  when /^((s|S)u)|((s|S)un)(day|days)*$/; Month.dates(year, month, :day => 'Sunday')
  else; super(method_name, *args, &block)
  end
end

Instance Attribute Details

#monthObject (readonly)

Returns the value of attribute month.



13
14
15
# File 'lib/Month/initialize.rb', line 13

def month
  @month
end

#yearObject (readonly)

Returns the value of attribute year.



13
14
15
# File 'lib/Month/initialize.rb', line 13

def year
  @year
end

Class Method Details

.begin_date(*args) ⇒ Object Also known as: start_date



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/Month/self.begin_date.rb', line 9

def begin_date(*args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  fail unless (1..12).include?(month)
  Date.new(year, month, 1)
end

.beginningObject Also known as: beginning_of_month, beginning_of_the_month



9
# File 'lib/Month/self.beginning.rb', line 9

alias_method :beginning, :begin_date

.cdate(which_day, day, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/Month/self.cdate.rb', line 10

def cdate(which_day, day, *args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size + 2} for 2, 3, or 4)"
    end
  )
  fail unless (1..12).include?(month)
  all = self.cdates(year, month, :day => day)
  case which_day.to_s.downcase
  when 'first', '1st', '1'; all[0]
  when 'second', '2nd', '2'; all[1]
  when 'third', '3rd', '3'; all[2]
  when 'fourth', '4th', '4'; all[3]
  when 'fifth', '5th', '5'; all[4]
  when 'last', 'ultimate'; all[all.size - 1]
  when 'second last', '2nd last', 'penultimate'; all[all.size - 2]
  when 'third last', '3rd last'; all[all.size - 3]
  when 'fourth last', '4th last'; all[all.size - 4]
  else; nil
  end
end

.cdates(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/Month/self.cdates.rb', line 13

def cdates(*args)
  options = args.extract_options!
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  list_of_dates = []
  month = self.to_num(month)
  return nil if month.nil?
  unless options[:day].nil?
    if e = ISO_8601_WEEK_DAY_NAMES_LONG.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
    elsif e = ISO_8601_WEEK_DAY_NAMES_SHORT.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
    elsif e = ISO_8601_WEEK_DAY_NAMES_SHORTEST.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
    elsif ISO_8601_WEEK_DAY_NUMBERS_AS_STRINGS.to_a.member?(options[:day]); weekday_number = options[:day].to_i
    elsif ISO_8601_WEEK_DAY_NUMBERS.to_a.member?(options[:day].to_i) && options[:day].class == Integer; weekday_number = options[:day].to_i
    else; return nil
    end
    Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
      if options[:date_objects]
        list_of_dates << date if date.cwday == weekday_number
      else
        list_of_dates << date.mday if date.cwday == weekday_number
      end
    end
  else
    Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
      if options[:date_objects]
        list_of_dates << date
      else
        list_of_dates << date.mday
      end
    end
  end
  list_of_dates
end

.date(which_day, day, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/Month/self.date.rb', line 10

def date(which_day, day, *args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 2, 3, or 4)"
    end
  )
  fail unless (1..12).include?(month)
  all = self.dates(year, month, :day => day)
  case which_day.to_s.downcase
  when 'first', '1st', '1'; all[0]
  when 'second', '2nd', '2'; all[1]
  when 'third', '3rd', '3'; all[2]
  when 'fourth', '4th', '4'; all[3]
  when 'fifth', '5th', '5'; all[4]
  when 'last', 'ultimate'; all[all.size - 1]
  when 'second last', '2nd last', 'penultimate'; all[all.size - 2]
  when 'third last', '3rd last'; all[all.size - 3]
  when 'fourth last', '4th last'; all[all.size - 4]
  else; nil
  end
end

.dates(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/Month/self.dates.rb', line 13

def dates(*args)
  options = args.extract_options!
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  list_of_dates = []
  month = self.to_num(month)
  return nil if month.nil?
  unless options[:day].nil?
    if e = WEEK_DAY_NAMES_LONG.to_a.index(options[:day].to_s.capitalize); weekday_number = e
    elsif e = WEEK_DAY_NAMES_SHORT.to_a.index(options[:day].to_s.capitalize); weekday_number = e 
    elsif e = WEEK_DAY_NAMES_SHORTEST.to_a.index(options[:day].to_s.capitalize); weekday_number = e 
    elsif WEEK_DAY_NUMBERS_AS_STRINGS.to_a.member?(options[:day]); weekday_number = options[:day].to_i
    elsif WEEK_DAY_NUMBERS.to_a.member?(options[:day].to_i) && options[:day].class == Integer; weekday_number = options[:day].to_i
    else; return nil
    end
    Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
      if options[:date_objects]
        list_of_dates << date if date.wday == weekday_number
      else
        list_of_dates << date.mday if date.wday == weekday_number
      end
    end
  else
    Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
      if options[:date_objects]
        list_of_dates << date
      else
        list_of_dates << date.mday
      end
    end
  end
  list_of_dates
end

.day(date, month = Date.today.month, year = Date.today.year) ⇒ Object Also known as: day_long



10
11
12
13
14
15
16
17
# File 'lib/Month/self.day.rb', line 10

def day(date, month = Date.today.month, year = Date.today.year)
  date, month, year = date.to_i, self.to_num(month), year.to_i
  if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
    WEEK_DAY_NAMES_LONG[Date.new(year, month, date).wday]
  else
    nil
  end
end

.day_short(date, month = Date.today.month, year = Date.today.year) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/self.day_short.rb', line 10

def day_short(date, month = Date.today.month, year = Date.today.year)
  date, month, year = date.to_i, self.to_num(month), year.to_i
  if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
    WEEK_DAY_NAMES_SHORT[Date.new(year, month, date).wday]
  else
    nil
  end
end

.day_shortest(date, month = Date.today.month, year = Date.today.year) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/self.day_shortest.rb', line 10

def day_shortest(date, month = Date.today.month, year = Date.today.year)
  date, month, year = date.to_i, self.to_num(month), year.to_i
  if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
    WEEK_DAY_NAMES_SHORTEST[Date.new(year, month, date).wday]
  else
    nil
  end
end

.days(*args) ⇒ Object Also known as: days_in_month, days_in_the_month



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/Month/self.days.rb', line 11

def days(*args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  if i = to_num(month)
    case e = MONTH_DAYS[i - 1]
    when Integer; e
    else; e.call(year)
    end
  else
    nil
  end
end

.endObject



9
# File 'lib/Month/self.end.rb', line 9

alias_method :end, :end_date

.end_date(*args) ⇒ Object Also known as: finish_date, end_of_month, end_of_the_month



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/Month/self.end_date.rb', line 10

def end_date(*args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  fail unless (1..12).include?(month)
  Date.new(year, month, self.days(year, month))
end

.from_date(date) ⇒ Object



9
10
11
# File 'lib/Month/self.from_date.rb', line 9

def from_date(date)
  Month.new(date.year, date.month)
end

.lastObject



9
# File 'lib/Month/self.last.rb', line 9

alias_method :last, :last_month

.last_year(month = Month.new) ⇒ Object



10
11
12
# File 'lib/Month/self.last_year.rb', line 10

def self.last_year(month = Month.new)
  month.last_year
end

.method_missing(method_name, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/Month/self.method_missing.rb', line 9

def method_missing(method_name, *args, &block)
  if month_object = self.of(method_name, *args, &block)
    month_object
  elsif days = Month.new.send(method_name, *args, &block)
    days
  else
    super(method_name, *args, &block)
  end
end

.next(*args) ⇒ Object Also known as: succ, successor, next_month, succ_month, successor_month



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/Month/self.next.rb', line 10

def next(*args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  fail unless (1..12).include?(month)
  if month == 12
    Month.new(year + 1, 1)
  else
    Month.new(year, month + 1)
  end
end

.next_year(month = Month.new) ⇒ Object



10
11
12
# File 'lib/Month/self.next_year.rb', line 10

def self.next_year(month = Month.new)
  month.next_year
end

.nowObject



9
# File 'lib/Month/self.now.rb', line 9

alias_method :now, :today

.of(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/Month/self.of.rb', line 10

def of(*args)
  year, month = (
    case args.size
    # when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  case month.to_s
  when /^(J|j)an(uary)*$/; new(year, 1)
  when /^(F|f)eb(ruary)*$/; new(year, 2)
  when /^(M|m)ar(ch)*$/; new(year, 3)
  when /^(A|a)pr(il)*$/; new(year, 4)
  when /^(M|m)ay$/; new(year, 5)
  when /^(J|j)un(e)*$/; new(year, 6)
  when /^(J|j)ul(y)*$/; new(year, 7)
  when /^(A|a)ug(ust)*$/; new(year, 8)
  when /^(S|s)ep(tember)*$/; new(year, 9)
  when /^(O|o)ct(ober)*$/; new(year, 10)
  when /^(N|n)ov(ember)*$/; new(year, 11)
  when /^(D|d)ec(ember)*$/; new(year, 12)
  else; nil
  end
end

.prev(*args) ⇒ Object Also known as: prior, previous, last_month, prev_month, prior_month, previous_month



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/Month/self.prev.rb', line 10

def prev(*args)
  year, month = (
    case args.size
    when 0; [Date.today.year, Date.today.month]
    when 1; [Date.today.year, args[0]]
    when 2; [args[0], args[1]]
    else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
    end
  )
  fail unless (1..12).include?(month)
  if month == 1
    Month.new(year - 1, 12)
  else
    Month.new(year, month - 1)
  end
end

.startObject



9
# File 'lib/Month/self.start.rb', line 9

alias_method :start, :start_date

.thisObject



10
11
12
# File 'lib/Month/self.this.rb', line 10

def this
  Month.new(Date.today.month)
end

.to_iObject



10
# File 'lib/Month/self.to_i.rb', line 10

alias_method :to_i, :to_num

.to_long(month = Date.today.month) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/self.to_long.rb', line 10

def to_long(month = Date.today.month)
  if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); MONTH_NAMES_LONG[i]
  elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); MONTH_NAMES_LONG[i]
  elsif i = MONTH_NUMBERS.to_a.index(month); MONTH_NAMES_LONG[i]
  elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); MONTH_NAMES_LONG[i]
  else; nil
  end
end

.to_num(month = Date.today.month) ⇒ Object Also known as: to_number



10
11
12
13
14
15
16
17
# File 'lib/Month/self.to_num.rb', line 10

def to_num(month = Date.today.month)
  if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); i + 1
  elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); i + 1
  elsif i = MONTH_NUMBERS.to_a.index(month); i + 1
  elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); i + 1
  else; nil
  end
end

.to_short(month = Date.today.month) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/self.to_short.rb', line 10

def to_short(month = Date.today.month)
  if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); MONTH_NAMES_SHORT[i]
  elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); MONTH_NAMES_SHORT[i]
  elsif i = MONTH_NUMBERS.to_a.index(month); MONTH_NAMES_SHORT[i]
  elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); MONTH_NAMES_SHORT[i]
  else; nil
  end
end

.todayObject



8
9
10
# File 'lib/Month/self.today.rb', line 8

def self.today
  new
end

.wday(date, month = Date.today.month, year = Date.today.year) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/self.wday.rb', line 10

def wday(date, month = Date.today.month, year = Date.today.year)
  date, month, year = date.to_i, self.to_num(month), year.to_i
  if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
    Date.new(year, month, date).wday
  else
    nil
  end
end

Instance Method Details

#<=>(other_month) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/Month/_comparator.rb', line 10

def <=>(other_month)
  if year == other_month.year
    month <=> other_month.month
  else
    year <=> other_month.year
  end
end

#begin_dateObject



9
10
11
# File 'lib/Month/begin_date.rb', line 9

def begin_date
  Month.begin_date(year, month)
end

#beginningObject



9
10
11
# File 'lib/Month/beginning.rb', line 9

def beginning
  Month.beginning(year, month)
end

#beginning_of_monthObject



9
10
11
# File 'lib/Month/beginning_of_month.rb', line 9

def beginning_of_month
  Month.beginning_of_month(year, month)
end

#beginning_of_the_monthObject



9
10
11
# File 'lib/Month/beginning_of_the_month.rb', line 9

def beginning_of_the_month
  Month.beginning_of_the_month(year, month)
end

#cdate(which_day, day) ⇒ Object



9
10
11
# File 'lib/Month/cdate.rb', line 9

def cdate(which_day, day)
  Month.cdate(which_day, day, year, month)
end

#cdates(day = nil) ⇒ Object



9
10
11
# File 'lib/Month/cdates.rb', line 9

def cdates(day = nil)
  Month.cdates(year, month, :day => day)
end

#date(which_day, day) ⇒ Object



9
10
11
# File 'lib/Month/date.rb', line 9

def date(which_day, day)
  Month.date(which_day, day, year, month)
end

#dates(day = nil) ⇒ Object



9
10
11
# File 'lib/Month/dates.rb', line 9

def dates(day = nil)
  Month.dates(year, month, :day => day)
end

#day(date) ⇒ Object



8
9
10
# File 'lib/Month/day.rb', line 8

def day(date)
  Month.day(date, month, year)
end

#day_long(date) ⇒ Object



8
9
10
# File 'lib/Month/day_long.rb', line 8

def day_long(date)
  Month.day_long(date, month, year)
end

#day_short(date) ⇒ Object



8
9
10
# File 'lib/Month/day_short.rb', line 8

def day_short(date)
  Month.day_short(date, month, year)
end

#day_shortest(date) ⇒ Object



8
9
10
# File 'lib/Month/day_shortest.rb', line 8

def day_shortest(date)
  Month.day_shortest(date, month, year)
end

#daysObject Also known as: days_in_month, days_in_the_month



9
10
11
# File 'lib/Month/days.rb', line 9

def days
  Month.days(year, month)
end

#each_dayObject



9
10
11
# File 'lib/Month/each_day.rb', line 9

def each_day
  (1..days).each{|day| yield day}
end

#endObject



9
10
11
# File 'lib/Month/end.rb', line 9

def end
  Month.end(year, month)
end

#end_dateObject



9
10
11
# File 'lib/Month/end_date.rb', line 9

def end_date
  Month.end_date(year, month)
end

#end_of_monthObject



9
10
11
# File 'lib/Month/end_of_month.rb', line 9

def end_of_month
  Month.end_of_month(year, month)
end

#end_of_the_monthObject



9
10
11
# File 'lib/Month/end_of_the_month.rb', line 9

def end_of_the_month
  Month.end_of_the_month(year, month)
end

#eql?(other_month) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


6
7
8
# File 'lib/Month/eqlQ.rb', line 6

def eql?(other_month)
  self.year == other_month.year && self.month == other_month.month
end

#finishObject



9
10
11
# File 'lib/Month/finish.rb', line 9

def finish
  Month.finish(year, month)
end

#finish_dateObject



9
10
11
# File 'lib/Month/finish_date.rb', line 9

def finish_date
  Month.finish_date(year, month)
end

#finish_of_monthObject



9
10
11
# File 'lib/Month/finish_of_month.rb', line 9

def finish_of_month
  Month.finish_of_month(year, month)
end

#finish_of_the_monthObject



9
10
11
# File 'lib/Month/finish_of_the_month.rb', line 9

def finish_of_the_month
  Month.finish_of_the_month(year, month)
end

#hashObject



8
9
10
# File 'lib/Month/hash.rb', line 8

def hash
  "#{year}#{month}".to_i
end

#lastObject



9
10
11
# File 'lib/Month/last.rb', line 9

def last
  Month.last(year, month)
end

#last_monthObject



9
10
11
# File 'lib/Month/last_month.rb', line 9

def last_month
  Month.last_month(year, month)
end

#last_yearObject



9
10
11
# File 'lib/Month/last_year.rb', line 9

def last_year
  Month.new(self.year - 1, self.month)
end

#minus(subtracted_months) ⇒ Object Also known as: -



8
9
10
11
12
13
14
15
16
17
# File 'lib/Month/minus.rb', line 8

def minus(subtracted_months)
  subtracted_years, remaining_months = subtracted_months.divmod(12)
  preliminary_year = self.year - subtracted_years
  if self.month > remaining_months
    year, month = preliminary_year, self.month - remaining_months
  else
    year, month = preliminary_year - 1, 12 - (remaining_months - self.month)
  end
  Month.new(year, month)
end

#nextObject



9
10
11
# File 'lib/Month/next.rb', line 9

def next
  Month.next(year, month)
end

#next_monthObject



9
10
11
# File 'lib/Month/next_month.rb', line 9

def next_month
  Month.next_month(year, month)
end

#next_yearObject



9
10
11
# File 'lib/Month/next_year.rb', line 9

def next_year
  Month.new(self.year + 1, self.month)
end

#plus(added_months) ⇒ Object Also known as: +



8
9
10
11
12
13
# File 'lib/Month/plus.rb', line 8

def plus(added_months)
  added_years, remaining_months = added_months.divmod(12)
  overflow_year, month = (self.month + remaining_months).divmod(12)
  year = self.year + added_years + overflow_year
  Month.new(year, month)
end

#prevObject



9
10
11
# File 'lib/Month/prev.rb', line 9

def prev
  Month.prev(year, month)
end

#prev_monthObject



9
10
11
# File 'lib/Month/prev_month.rb', line 9

def prev_month
  Month.prev_month(year, month)
end

#previousObject



9
10
11
# File 'lib/Month/previous.rb', line 9

def previous
  Month.previous(year, month)
end

#previous_monthObject



9
10
11
# File 'lib/Month/previous_month.rb', line 9

def previous_month
  Month.previous_month(year, month)
end

#priorObject



8
9
10
# File 'lib/Month/prior.rb', line 8

def prior
  Month.prior(year, month)
end

#prior_monthObject



9
10
11
# File 'lib/Month/prior_month.rb', line 9

def prior_month
  Month.prior_month(year, month)
end

#startObject



9
10
11
# File 'lib/Month/start.rb', line 9

def start
  Month.start(year, month)
end

#start_dateObject



9
10
11
# File 'lib/Month/start_date.rb', line 9

def start_date
  Month.start_date(year, month)
end

#start_of_monthObject



9
10
11
# File 'lib/Month/start_of_month.rb', line 9

def start_of_month
  Month.start_of_month(year, month)
end

#start_of_the_monthObject



9
10
11
# File 'lib/Month/start_of_the_month.rb', line 9

def start_of_the_month
  Month.start_of_the_month(year, month)
end

#succObject



9
10
11
# File 'lib/Month/succ.rb', line 9

def succ
  Month.succ(year, month)
end

#succ_monthObject



9
10
11
# File 'lib/Month/succ_month.rb', line 9

def succ_month
  Month.succ_month(year, month)
end

#successorObject



9
10
11
# File 'lib/Month/successor.rb', line 9

def successor
  Month.successor(year, month)
end

#successor_monthObject



9
10
11
# File 'lib/Month/successor_month.rb', line 9

def successor_month
  Month.successor_month(year, month)
end

#to_dateObject



9
10
11
# File 'lib/Month/to_date.rb', line 9

def to_date
  Date.new(year, month, 1)
end

#to_iObject



9
10
11
# File 'lib/Month/to_i.rb', line 9

def to_i
  Month.to_i(month)
end

#to_longObject



9
10
11
# File 'lib/Month/to_long.rb', line 9

def to_long
  Month.to_long(month)
end

#to_numObject



9
10
11
# File 'lib/Month/to_num.rb', line 9

def to_num
  Month.to_num(month)
end

#to_numberObject



9
10
11
# File 'lib/Month/to_number.rb', line 9

def to_number
  Month.to_number(month)
end

#to_s(month_name_length = :long) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/Month/to_s.rb', line 10

def to_s(month_name_length = :long)
  case (month_name_length.to_sym if month_name_length.respond_to?(:to_sym))
  when :long; "#{to_long} #{year}"
  when :short; "#{to_short} #{year}"
  when :iso, :iso_8601; "#{year}-" + "%02d" % month
  else; raise ArgumentError, "unknown month name length #{month_name_length.inspect} (expected :long, :short, :iso, or :iso_8601)"
  end
end

#to_shortObject



9
10
11
# File 'lib/Month/to_short.rb', line 9

def to_short
  Month.to_short(month)
end