ranged_find 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/dreamer3/ranged_find.rb +14 -9
  2. metadata +6 -7
@@ -1,7 +1,7 @@
1
1
  module Dreamer3 # :nodoc:
2
2
  module RangedFind # :nodoc:
3
3
 
4
- DATE_RANGES= lambda {{
4
+ DATE_RANGES = lambda {{
5
5
  # daily
6
6
  :yesterday => [ Time.zone.now.yesterday.midnight, 1.day ],
7
7
  :today => [ Time.zone.now.midnight, 1.day ],
@@ -28,13 +28,14 @@ module Dreamer3 # :nodoc:
28
28
 
29
29
  # returns a conditions array to scope a specific field to a certain time range
30
30
  def date_range_conditions(field, time_range)
31
- conditions = ["? <= #{field} and #{field} < ?"]
31
+ sql = ["? <= #{field} and #{field} < ?"]
32
+ actual_range = []
32
33
  if time_range.is_a?(Range)
33
- conditions << time_range.begin
34
- conditions << time_range.end
34
+ actual_range << time_range.begin
35
+ actual_range << time_range.end
35
36
  elsif range=DATE_RANGES.call[time_range]
36
- conditions << range.first
37
- conditions << (range.last===Time ? range.last : range.first + range.last)
37
+ actual_range << range.first
38
+ actual_range << (range.last===Time ? range.last : range.first + range.last)
38
39
  else
39
40
  case time_range
40
41
  # calcuates the count of last month, but only as far as we are in the current month
@@ -45,13 +46,17 @@ module Dreamer3 # :nodoc:
45
46
  ratio=Time.zone.now.mday.to_f/end_of_this_month
46
47
  end_date=Time.zone.now.prev_month.beginning_of_month.midnight+(ratio*end_of_last_month).days
47
48
 
48
- conditions << Time.zone.now.prev_month.beginning_of_month
49
- conditions << end_date
49
+ actual_range << Time.zone.now.prev_month.beginning_of_month
50
+ actual_range << end_date
50
51
  else
51
52
  raise "invalid date range provided"
52
53
  end
53
54
  end
54
- conditions
55
+ # date
56
+ if field =~ /_on$/
57
+ actual_range = actual_range.map {|x| x.to_date}
58
+ end
59
+ sql + actual_range
55
60
  end
56
61
 
57
62
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ranged_find
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josh Goebel
@@ -14,8 +14,7 @@ autorequire: ranged_find
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-12-23 00:00:00 -05:00
18
- default_executable:
17
+ date: 2014-04-17 00:00:00 Z
19
18
  dependencies: []
20
19
 
21
20
  description: Helpler for making date range queries easier in Rails
@@ -32,7 +31,6 @@ files:
32
31
  - lib/ranged_find.rb
33
32
  - MIT-LICENSE
34
33
  - README
35
- has_rdoc: true
36
34
  homepage: https://github.com/yyyc514/ranged_find
37
35
  licenses: []
38
36
 
@@ -62,9 +60,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
60
  requirements:
63
61
  - none
64
62
  rubyforge_project:
65
- rubygems_version: 1.6.2
63
+ rubygems_version: 1.8.15
66
64
  signing_key:
67
65
  specification_version: 3
68
66
  summary: Helpler for making date range queries easier in Rails
69
67
  test_files: []
70
68
 
69
+ has_rdoc: