Skip to content

Commit

Permalink
Consolidate files
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Jan 12, 2014
1 parent 9a47562 commit 5f54cd0
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 132 deletions.
13 changes: 3 additions & 10 deletions lib/by_star.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
27 changes: 8 additions & 19 deletions lib/by_star/base.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
80 changes: 80 additions & 0 deletions lib/by_star/between.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions lib/by_star/by_calendar_month.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/by_star/by_day.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/by_star/by_fortnight.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/by_star/by_month.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/by_star/by_quarter.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/by_star/by_week.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/by_star/by_weekend.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/by_star/by_year.rb

This file was deleted.

3 changes: 2 additions & 1 deletion lib/by_star/by_direction.rb → lib/by_star/directional.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ByStar
module ByDirection

module Directional

def before(*args)
with_by_star_options(*args) do |time, options|
Expand Down
2 changes: 2 additions & 0 deletions lib/by_star/kernel/time.rb → lib/by_star/kernel.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 5f54cd0

Please sign in to comment.