fortnight 0.0.1rc1 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/LICENSE +1 -1
- data/README.md +13 -31
- data/fortnight.gemspec +0 -2
- data/lib/fortnight.rb +11 -16
- data/lib/fortnight/version.rb +1 -1
- metadata +6 -22
data/.gitignore
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,47 +1,29 @@
|
|
1
1
|
# Fortnight
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
The gem work separing the month of a year in two half, first - 15th and 16th - last day
|
3
|
+
TODO: Write a gem description
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
Add
|
7
|
+
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
gem 'fortnight'
|
12
10
|
|
13
|
-
|
11
|
+
And then execute:
|
14
12
|
|
15
|
-
$ bundle
|
13
|
+
$ bundle
|
16
14
|
|
17
|
-
|
15
|
+
Or install it yourself as:
|
18
16
|
|
19
|
-
|
17
|
+
$ gem install fortnight
|
20
18
|
|
21
19
|
## Usage
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
Model.in_fortnight(year, month, options)
|
26
|
-
|
27
|
-
'options' for now are only :field and :half
|
28
|
-
:field ALWAYS HAVE TO BE A TIME FIELD
|
29
|
-
:half is to get the first (by default) or the second (as symbol)
|
30
|
-
|
31
|
-
Examples:
|
32
|
-
|
33
|
-
Customer.in_fortnight(2012, 04)
|
34
|
-
We'll get the customers created_at between 2012-04-01 00:00 AND 2012-04-15 23:59:59
|
35
|
-
|
36
|
-
Customer.in_fortnight(2012, 04, half: :second)
|
37
|
-
We'll get the customers created_at between 2012-04-15 23:59:59 AND 2012-04-30 23:59:59
|
38
|
-
|
39
|
-
Customer.in_fortnight(2012, 05, half: :second)
|
40
|
-
We'll get the customers created_at between 2012-05-15 23:59:59 AND 2012-05-31 23:59:59
|
41
|
-
|
42
|
-
Customer.in_fortnight(2012, 04, field: 'updated_at')
|
43
|
-
We'll get the customers updated_at between 2012-04-01 00:00 AND 2012-04-15 23:59
|
21
|
+
TODO: Write usage instructions here
|
44
22
|
|
45
|
-
|
46
|
-
We'll get the customers updated_at between 2012-04-15 23:59:59 AND 2012-04-30 23:59:59
|
23
|
+
## Contributing
|
47
24
|
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/fortnight.gemspec
CHANGED
data/lib/fortnight.rb
CHANGED
@@ -1,24 +1,19 @@
|
|
1
1
|
require "fortnight/version"
|
2
2
|
|
3
3
|
module Fortnight
|
4
|
-
|
5
|
-
clase.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def in_fortnight(year, month, options={})
|
4
|
+
def in_fortnight(year, month, options={})
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin_of_month = Time.new(year, month)
|
7
|
+
half_of_month = begin_of_month.advance(days: 14).end_of_day
|
8
|
+
final_of_month = begin_of_month.end_of_month.end_of_day
|
14
9
|
|
15
|
-
|
16
|
-
|
10
|
+
start = options[:half] == :second ? half_of_month : begin_of_month
|
11
|
+
finish = options[:half] == :second ? final_of_month : half_of_month
|
17
12
|
|
18
|
-
|
13
|
+
field = options[:field] || 'created_at'
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
15
|
+
scope = where("#{field} >= :s AND #{field} <= :f", s: start, f: finish)
|
16
|
+
scope = scope.order(options[:order]) if options[:order]
|
17
|
+
scope
|
24
18
|
end
|
19
|
+
end
|
data/lib/fortnight/version.rb
CHANGED
metadata
CHANGED
@@ -1,32 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortnight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Néstor Coppi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rails
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 3.1.0
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.1.0
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: Scope to difference by first and second half month
|
31
15
|
email:
|
32
16
|
- nestorcoppi@gmail.com
|
@@ -57,9 +41,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
42
|
none: false
|
59
43
|
requirements:
|
60
|
-
- - ! '
|
44
|
+
- - ! '>='
|
61
45
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
46
|
+
version: '0'
|
63
47
|
requirements: []
|
64
48
|
rubyforge_project:
|
65
49
|
rubygems_version: 1.8.24
|