Sha256: 437fe6f50e12e05bbb220dd9d32db7fd99209cf02554717ff752326bd9ff1d21

Contents?: true

Size: 936 Bytes

Versions: 1

Compression:

Stored size: 936 Bytes

Contents

module ByStar
  module ByWeek

    # 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_week(*args)
      options = args.extract_options!.symbolize_keys!
      time = args.first
      time ||= Time.zone.local(options[:year], 1, 1) if options[:year]
      time ||= Time.zone.now
      send("by_week_#{time_klass(time)}", time, options)
    end

    private

    def by_week_Time(time, options={})
      between(time.beginning_of_week, time.end_of_week, options)
    end

    def by_week_Date(date, options={})
      by_week_Time(date.to_time, options)
    end

    def by_week_Fixnum(week, options={})
      time = Time.zone.local(options[:year], 1, 1) if options[:year]
      time ||= Time.zone.now
      start_time = time.beginning_of_year + week.to_i.weeks
      between(start_time, (start_time + 1.week).end_of_day, options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.1.0.beta2 lib/by_star/by_week.rb