Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Consolidate files

  • Loading branch information...
commit 5f54cd0a13b2a728df2b425d1f1fdfe881d43de9 1 parent 9a47562
@johnnyshields johnnyshields authored
View
13 lib/by_star.rb
@@ -1,14 +1,7 @@
-require 'by_star/kernel/time'
+require 'by_star/kernel'
require 'by_star/normalization'
-require 'by_star/by_direction'
-require 'by_star/by_year'
-require 'by_star/by_month'
-require 'by_star/by_calendar_month'
-require 'by_star/by_fortnight'
-require 'by_star/by_week'
-require 'by_star/by_weekend'
-require 'by_star/by_day'
-require 'by_star/by_quarter'
+require 'by_star/between'
+require 'by_star/directional'
require 'by_star/base'
if defined?(ActiveRecord)
View
27 lib/by_star/base.rb
@@ -1,20 +1,9 @@
module ByStar
module Base
- include ByStar::ByDirection
- include ByStar::ByYear
- include ByStar::ByMonth
- include ByStar::ByCalendarMonth
- include ByStar::ByFortnight
- include ByStar::ByWeek
- include ByStar::ByWeekend
- include ByStar::ByDay
- include ByStar::ByQuarter
- def between_times(start, finish, options={})
- offset = by_star_offset(options)
- between_times_query(start + offset, finish + offset, options)
- end
+ include ByStar::Between
+ include ByStar::Directional
def by_star_field(start_field = nil, end_field = nil, options = {})
@by_star_start_field ||= start_field
@@ -28,17 +17,17 @@ def by_star_offset(options = {})
def by_star_start_field(options={})
field = options[:field] ||
- options[:start_field] ||
- @by_star_start_field ||
- by_star_default_field
+ options[:start_field] ||
+ @by_star_start_field ||
+ by_star_default_field
field.to_s
end
def by_star_end_field(options={})
field = options[:field] ||
- options[:end_field] ||
- @by_star_end_field ||
- by_star_start_field
+ options[:end_field] ||
+ @by_star_end_field ||
+ by_star_start_field
field.to_s
end
View
80 lib/by_star/between.rb
@@ -0,0 +1,80 @@
+module ByStar
+
+ module Between
+
+ def between_times(start, finish, options={})
+ offset = by_star_offset(options)
+ between_times_query(start + offset, finish + offset, options)
+ end
+
+ def by_day(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.time(time)
+ between_times(time.beginning_of_day, time.end_of_day, options)
+ end
+ end
+
+ def today(options={})
+ by_day(Time.zone.now, options)
+ end
+
+ def yesterday(options={})
+ by_day(Time.zone.now.yesterday, options)
+ end
+
+ def tomorrow(options={})
+ by_day(Time.zone.now.tomorrow, options)
+ end
+
+ def by_week(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.week(time, options)
+ start_day = Array(options[:start_day])
+ between_times(time.beginning_of_week(*start_day), time.end_of_week(*start_day), options)
+ end
+ end
+
+ def by_weekend(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.week(time, options)
+ between_times(time.beginning_of_weekend, time.end_of_weekend, options)
+ end
+ end
+
+ def by_fortnight(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.fortnight(time, options)
+ between_times(time.beginning_of_fortnight, time.end_of_fortnight, options)
+ end
+ end
+
+ def by_month(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.month(time, options)
+ between_times(time.beginning_of_month, time.end_of_month, options)
+ end
+ end
+
+ def by_calendar_month(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.month(time, options)
+ start_day = Array(options[:start_day])
+ between_times(time.beginning_of_calendar_month(*start_day), time.end_of_calendar_month(*start_day), options)
+ end
+ end
+
+ def by_quarter(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.quarter(time, options)
+ between_times(time.beginning_of_quarter, time.end_of_quarter, options)
+ end
+ end
+
+ def by_year(*args)
+ with_by_star_options(*args) do |time, options|
+ time = ByStar::Normalization.year(time, options)
+ between_times(time.beginning_of_year, time.end_of_year, options)
+ end
+ end
+ end
+end
View
12 lib/by_star/by_calendar_month.rb
@@ -1,12 +0,0 @@
-module ByStar
- module ByCalendarMonth
-
- def by_calendar_month(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.month(time, options)
- start_day = Array(options[:start_day])
- between_times(time.beginning_of_calendar_month(*start_day), time.end_of_calendar_month(*start_day), options)
- end
- end
- end
-end
View
23 lib/by_star/by_day.rb
@@ -1,23 +0,0 @@
-module ByStar
- module ByDay
-
- def by_day(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.time(time)
- between_times(time.beginning_of_day, time.end_of_day, options)
- end
- end
-
- def today(options={})
- by_day(Time.zone.now, options)
- end
-
- def yesterday(options={})
- by_day(Time.zone.now.yesterday, options)
- end
-
- def tomorrow(options={})
- by_day(Time.zone.now.tomorrow, options)
- end
- end
-end
View
11 lib/by_star/by_fortnight.rb
@@ -1,11 +0,0 @@
-module ByStar
- module ByFortnight
-
- def by_fortnight(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.fortnight(time, options)
- between_times(time.beginning_of_fortnight, time.end_of_fortnight, options)
- end
- end
- end
-end
View
11 lib/by_star/by_month.rb
@@ -1,11 +0,0 @@
-module ByStar
- module ByMonth
-
- def by_month(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.month(time, options)
- between_times(time.beginning_of_month, time.end_of_month, options)
- end
- end
- end
-end
View
11 lib/by_star/by_quarter.rb
@@ -1,11 +0,0 @@
-module ByStar
- module ByQuarter
-
- def by_quarter(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.quarter(time, options)
- between_times(time.beginning_of_quarter, time.end_of_quarter, options)
- end
- end
- end
-end
View
12 lib/by_star/by_week.rb
@@ -1,12 +0,0 @@
-module ByStar
- module ByWeek
-
- def by_week(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.week(time, options)
- start_day = Array(options[:start_day])
- between_times(time.beginning_of_week(*start_day), time.end_of_week(*start_day), options)
- end
- end
- end
-end
View
11 lib/by_star/by_weekend.rb
@@ -1,11 +0,0 @@
-module ByStar
- module ByWeekend
-
- def by_weekend(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.week(time, options)
- between_times(time.beginning_of_weekend, time.end_of_weekend, options)
- end
- end
- end
-end
View
11 lib/by_star/by_year.rb
@@ -1,11 +0,0 @@
-module ByStar
- module ByYear
-
- def by_year(*args)
- with_by_star_options(*args) do |time, options|
- time = ByStar::Normalization.year(time, options)
- between_times(time.beginning_of_year, time.end_of_year, options)
- end
- end
- end
-end
View
3  lib/by_star/by_direction.rb → lib/by_star/directional.rb
@@ -1,5 +1,6 @@
module ByStar
- module ByDirection
+
+ module Directional
def before(*args)
with_by_star_options(*args) do |time, options|
View
2  lib/by_star/kernel/time.rb → lib/by_star/kernel.rb
@@ -1,5 +1,7 @@
module ByStar
+
module Kernel
+
module Time
# A "Weekend" is defined as the 60-hour period from 15:00 Friday to 03:00 Monday.
Please sign in to comment.
Something went wrong with that request. Please try again.