cada 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.
@@ -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 cada.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 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.
@@ -0,0 +1,47 @@
1
+ # Cada
2
+
3
+ Easy to read helpers to execute something every month, day, etc. This is not a scheduler. Best understood by:
4
+
5
+ Cada.month '2012-01-03'.to_date, '2012-04-01' do |date|
6
+ puts "#{date.month}, #{date.day}"
7
+ end
8
+
9
+ The above will output:
10
+
11
+ 1, 3
12
+ 2, 3
13
+ 3, 3
14
+
15
+ You can use anything that Numeric responds to. For example, these will work:
16
+
17
+ - second/s
18
+ - minute/s
19
+ - week/s
20
+ - month/s
21
+ - fortnight/s
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'cada'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install cada
36
+
37
+ ## Usage
38
+
39
+ TODO: Write usage instructions here
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cada/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cada"
8
+ spec.version = Cada::VERSION
9
+ spec.authors = ["Ramon Tayag"]
10
+ spec.email = ["ramon.tayag@gmail.com"]
11
+ spec.description = %q{Loop through dates (every day, every week, every month, etc)}
12
+ spec.summary = %q{Step through a date by a timeframe}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport', '~> 3.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", '2.13.0'
26
+ end
@@ -0,0 +1,9 @@
1
+ require "cada/version"
2
+ require 'active_support/core_ext/numeric'
3
+ require 'cada/stepper'
4
+
5
+ module Cada
6
+ def self.method_missing(method_name, *args, &block)
7
+ Stepper.send(method_name, *args, &block)
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ module Cada
2
+ class Stepper
3
+
4
+ def self.method_missing(method_name, *args, &block)
5
+ if 1.respond_to?(method_name)
6
+ start_date, end_date = args
7
+ self.new(method_name, start_date, end_date, &block).step
8
+ else
9
+ message = '`meh` is not a valid range. Use `day`, `month`, `week`, etc'
10
+ fail NoMethodError, message
11
+ end
12
+ end
13
+
14
+ def initialize(range, start_date, end_date, &block)
15
+ @range = range
16
+ @start_date = start_date
17
+ @end_date = end_date
18
+ @block = block
19
+ end
20
+
21
+ def step
22
+ current_date = @start_date
23
+ while current_date <= @end_date
24
+ @block.call(current_date)
25
+ current_date += 1.send(@range)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Cada
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cada do
4
+
5
+ describe '#day' do
6
+ it 'should step per day between the start and end dates and execute the block' do
7
+ steps = []
8
+ described_class.day '2011-02-02'.to_date, '2011-02-03'.to_date do |date|
9
+ steps << date
10
+ end
11
+
12
+ steps.size.should == 2
13
+ steps[0].should == '2011-02-02'.to_date
14
+ steps[1].should == '2011-02-03'.to_date
15
+ end
16
+ end
17
+
18
+ describe '#month' do
19
+ it 'should step per month between the start and end dates and execute the block' do
20
+ steps = []
21
+ described_class.month '2011-02-02'.to_date, '2011-04-04'.to_date do |date|
22
+ steps << date
23
+ end
24
+
25
+ steps.size.should == 3
26
+ steps[0].should == '2011-02-02'.to_date
27
+ steps[1].should == '2011-03-02'.to_date
28
+ steps[2].should == '2011-04-02'.to_date
29
+ end
30
+ end
31
+
32
+ it 'should raise an error if a date range used does not exist' do
33
+ expect {
34
+ described_class.meh 1.day.ago, 1.day.ago
35
+ }.to raise_error(
36
+ NoMethodError,
37
+ '`meh` is not a valid range. Use `day`, `month`, `week`, etc'
38
+ )
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:test)
3
+
4
+ require 'rubygems'
5
+ require 'active_support/all'
6
+ require 'cada'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cada
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ramon Tayag
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.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.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ description: Loop through dates (every day, every week, every month, etc)
79
+ email:
80
+ - ramon.tayag@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - cada.gemspec
91
+ - lib/cada.rb
92
+ - lib/cada/stepper.rb
93
+ - lib/cada/version.rb
94
+ - spec/cada_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -4177211542693863245
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -4177211542693863245
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.25
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Step through a date by a timeframe
127
+ test_files:
128
+ - spec/cada_spec.rb
129
+ - spec/spec_helper.rb