fortnight 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ /nbproject
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2012 Néstor Coppi
2
-
2
+ Gem for fortnights global-scope
3
3
  MIT License
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -1,29 +1,47 @@
1
1
  # Fortnight
2
2
 
3
- TODO: Write a gem description
3
+ Scope to difference by first and second half month.
4
+
5
+ The gem work separing the month of a year in two half, first - 15th and 16th - last day
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Add the gem to your Gemfile
8
10
 
9
11
  gem 'fortnight'
10
12
 
11
- And then execute:
13
+ and run:
12
14
 
13
- $ bundle
15
+ $ bundle install/update
14
16
 
15
- Or install it yourself as:
17
+ Add in the models that we want to use
16
18
 
17
- $ gem install fortnight
19
+ include Fortnight
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ It's very simple, the syntax is the next:
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
22
44
 
23
- ## Contributing
45
+ Customer.in_fortnight(2012, 04, half: :second, field: 'updated_at')
46
+ We'll get the customers updated_at between 2012-04-15 23:59:59 AND 2012-04-30 23:59:59
24
47
 
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
@@ -5,8 +5,8 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Néstor Coppi"]
6
6
  gem.email = ["nestorcoppi@gmail.com"]
7
7
  gem.description = %q{Scope to difference by first and second half month}
8
- gem.summary = %q{}
9
- gem.homepage = ""
8
+ gem.summary = %q{Scope to difference by first and second half month}
9
+ gem.homepage = "https://github.com/Shelvak/Fortnight"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "fortnight"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Fortnight::VERSION
17
+
18
+ gem.add_dependency 'rails', '>= 3.1.0'
17
19
  end
@@ -1,19 +1,28 @@
1
1
  require "fortnight/version"
2
2
 
3
3
  module Fortnight
4
- def in_fortnight(year, month, options={})
4
+
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def in_fortnight(year, month, options={})
5
11
 
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
12
+ begin_of_month = Time.new(year, month)
13
+ half_of_month = begin_of_month.advance(days: 14).end_of_day
14
+ final_of_month = begin_of_month.end_of_month.end_of_day
9
15
 
10
- start = options[:half] == :second ? half_of_month : begin_of_month
11
- finish = options[:half] == :second ? final_of_month : half_of_month
16
+ start = options[:half] == :second ? half_of_month : begin_of_month
17
+ finish = options[:half] == :second ? final_of_month : half_of_month
12
18
 
13
- field = options[:field] || 'created_at'
19
+ field = options[:field] || 'created_at'
14
20
 
15
- scope = where("#{field} >= :s AND #{field} <= :f", s: start, f: finish)
16
- scope = scope.order(options[:order]) if options[:order]
17
- scope
21
+ scope = where("#{field} >= :s AND #{field} <= :f", s: start, f: finish)
22
+ scope = scope.order(options[:order]) if options[:order]
23
+ scope
24
+ end
18
25
  end
19
26
  end
27
+
28
+
@@ -1,3 +1,3 @@
1
1
  module Fortnight
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortnight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-07-18 00:00:00.000000000 Z
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
14
30
  description: Scope to difference by first and second half month
15
31
  email:
16
32
  - nestorcoppi@gmail.com
@@ -26,7 +42,7 @@ files:
26
42
  - fortnight.gemspec
27
43
  - lib/fortnight.rb
28
44
  - lib/fortnight/version.rb
29
- homepage: ''
45
+ homepage: https://github.com/Shelvak/Fortnight
30
46
  licenses: []
31
47
  post_install_message:
32
48
  rdoc_options: []
@@ -49,5 +65,5 @@ rubyforge_project:
49
65
  rubygems_version: 1.8.24
50
66
  signing_key:
51
67
  specification_version: 3
52
- summary: ''
68
+ summary: Scope to difference by first and second half month
53
69
  test_files: []