Sha256: b1cd3a68ec408a02f91fa56b243e66a3869a4aa23d2df618eaf421e9782fe911

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module ByStar
  module ByMonth
    # For reasoning why I use *args rather than variables here,
    # please see the by_year method comments in lib/by_star/by_year.rb

    def by_month(*args)
      options = args.extract_options!
      time = args.first || Time.zone.now
      send("by_month_#{time_klass(time)}", time, options)
    end

    private

    def by_month_Time(time, options={})
      between(time.beginning_of_month, time.end_of_month, options)
    end

    def by_month_String_or_Fixnum(month, options={})
      if valid_month?(month)
        year = options[:year] || Time.zone.now.year
        by_month_Time("#{year}-#{month}-01".to_time, options)
      else
        raise ParseError, "Month must be a number between 1 and 12 or the full month name (e.g. 'January', 'Feburary', etc.)"
      end
    end
    alias_method :by_month_String, :by_month_String_or_Fixnum
    alias_method :by_month_Fixnum, :by_month_String_or_Fixnum


    def valid_month?(month)
      (1..12).include?(month) || Date::MONTHNAMES.include?(month)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.0.0.beta1 lib/by_star/by_month.rb