date_ranger 0.0.1

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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in date_ranger.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DateRanger
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'date_ranger'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install date_ranger
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
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/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/date_ranger/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nestor Pestelos and Ramon Tayag"]
6
+ gem.email = ["ngpestelos@gmail.com","ramon.tayag@gmail.com"]
7
+ gem.description = "Provides date range methods"
8
+ gem.summary = %q{Provides date range methods}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "date_ranger"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DateRanger::VERSION
17
+
18
+ gem.add_development_dependency "rspec", '~> 2.12.0'
19
+ gem.add_runtime_dependency "activesupport", '~> 3.0'
20
+ end
21
+
@@ -0,0 +1,12 @@
1
+ module DateRanger::Bootstrapper
2
+
3
+ def has_date_range(options={})
4
+ cattr_accessor :date_ranger_options
5
+ self.date_ranger_options = options
6
+ self.date_ranger_options[:timestep] ||= :daily
7
+ self.send :include, DateRanger
8
+ end
9
+
10
+ end
11
+
12
+ Class.send :include, DateRanger::Bootstrapper
@@ -0,0 +1,3 @@
1
+ module DateRanger
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ module DateRanger
2
+
3
+ def start_date
4
+ @start_date ||= self.class.date_ranger_options[:default_start_date].call
5
+ case self.class.date_ranger_options[:timestep]
6
+ when :daily; @start_date
7
+ when :monthly; @start_date.beginning_of_month
8
+ end
9
+ end
10
+
11
+ def start_date=(date)
12
+ @start_date = date.respond_to?(:to_date) ? date.to_date : date
13
+ end
14
+
15
+ def end_date
16
+ @end_date ||= self.class.date_ranger_options[:default_end_date].call
17
+ case self.class.date_ranger_options[:timestep]
18
+ when :daily; @end_date
19
+ when :monthly; @end_date.end_of_month
20
+ end
21
+ end
22
+
23
+ def end_date=(date)
24
+ @end_date = date.respond_to?(:to_date) ? date.to_date : date
25
+ end
26
+
27
+ end
28
+
29
+ require "active_support/all"
30
+ require "date_ranger/version"
31
+ require 'date_ranger/bootstrapper'
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe DateRanger do
4
+
5
+ class Something
6
+ end
7
+
8
+ describe '.has_date_range' do
9
+ it 'should default timestep to :daily' do
10
+ Something.has_date_range
11
+ Something.date_ranger_options[:timestep].should == :daily
12
+ end
13
+ end
14
+
15
+ describe "#start_date" do
16
+ it 'should return date given a string' do
17
+ Something.has_date_range
18
+ something = Something.new
19
+ something.start_date = '2012-01-01'
20
+ something.start_date.should == '2012-01-01'.to_date
21
+ end
22
+
23
+ context 'when not overriden' do
24
+ it 'should return the given default start date' do
25
+ Something.has_date_range :default_start_date => lambda { 2.days.ago.to_date }
26
+ something = Something.new
27
+ something.start_date.should == 2.days.ago.to_date
28
+ end
29
+ end
30
+
31
+ context 'when the timestep is monthly' do
32
+ it 'should start at the first day of the month' do
33
+ Something.has_date_range(:timestep => :monthly)
34
+ something = Something.new
35
+ something.start_date = '2012-01-05'.to_date
36
+ something.start_date.should == '2012-01-01'.to_date
37
+ end
38
+ end
39
+
40
+ context 'when the timestep is daily' do
41
+ it 'should end at the given date' do
42
+ Something.has_date_range(:timestep => :daily)
43
+ something = Something.new
44
+ something.start_date = '2012-01-15'.to_date
45
+ something.start_date.should == '2012-01-15'.to_date
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "#end_date" do
51
+ it 'should return date given a string' do
52
+ Something.has_date_range
53
+ something = Something.new
54
+ something.end_date = '2012-01-01'
55
+ something.end_date.should == '2012-01-01'.to_date
56
+ end
57
+
58
+ context 'when not overriden' do
59
+ it 'should return the given default end date' do
60
+ Something.has_date_range :default_end_date => lambda { 2.days.ago.to_date }
61
+ something = Something.new
62
+ something.end_date.should == 2.days.ago.to_date
63
+ end
64
+ end
65
+
66
+ context 'when the timestep is monthly' do
67
+ it 'should end at the last day of the month' do
68
+ Something.has_date_range(:timestep => :monthly)
69
+ something = Something.new
70
+ something.end_date = '2012-01-15'.to_date
71
+ something.end_date.should == '2012-01-31'.to_date
72
+ end
73
+ end
74
+
75
+ context 'when the timestep is daily' do
76
+ it 'should end at the given date' do
77
+ Something.has_date_range(:timestep => :daily)
78
+ something = Something.new
79
+ something.end_date = '2012-01-15'.to_date
80
+ something.end_date.should == '2012-01-15'.to_date
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,4 @@
1
+ require 'date_ranger'
2
+
3
+ #RSpec.configure do |config|
4
+ #end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: date_ranger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Nestor Pestelos and Ramon Tayag
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 63
27
+ segments:
28
+ - 2
29
+ - 12
30
+ - 0
31
+ version: 2.12.0
32
+ prerelease: false
33
+ type: :development
34
+ name: rspec
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 7
43
+ segments:
44
+ - 3
45
+ - 0
46
+ version: "3.0"
47
+ prerelease: false
48
+ type: :runtime
49
+ name: activesupport
50
+ requirement: *id002
51
+ description: Provides date range methods
52
+ email:
53
+ - ngpestelos@gmail.com
54
+ - ramon.tayag@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - date_ranger.gemspec
68
+ - lib/date_ranger.rb
69
+ - lib/date_ranger/bootstrapper.rb
70
+ - lib/date_ranger/version.rb
71
+ - spec/date_ranger_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ""
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Provides date range methods
106
+ test_files:
107
+ - spec/date_ranger_spec.rb
108
+ - spec/spec_helper.rb