recurrence 0.1.1 → 0.1.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.
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurrence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Nando Vieira
@@ -9,70 +15,96 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-18 00:00:00 -02:00
18
+ date: 2010-09-09 00:00:00 -03:00
13
19
  default_executable:
14
20
  dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :development
36
+ version_requirements: *id001
15
37
  - !ruby/object:Gem::Dependency
16
38
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
20
42
  requirements:
21
43
  - - ">="
22
44
  - !ruby/object:Gem::Version
23
- version: 2.1.1
24
- version:
25
- description:
26
- email:
27
- - fnando.vieira@gmail.com
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: ""
52
+ email: fnando.vieira@gmail.com
28
53
  executables: []
29
54
 
30
55
  extensions: []
31
56
 
32
- extra_rdoc_files: []
33
-
57
+ extra_rdoc_files:
58
+ - README.markdown
34
59
  files:
35
- - init.rb
36
- - Rakefile
37
- - recurrence.gemspec
38
60
  - History.txt
39
61
  - License.txt
40
62
  - README.markdown
41
- - lib/recurrence/base.rb
63
+ - Rakefile
64
+ - init.rb
65
+ - lib/recurrence.rb
66
+ - lib/recurrence/event.rb
67
+ - lib/recurrence/event/base.rb
42
68
  - lib/recurrence/event/daily.rb
43
69
  - lib/recurrence/event/monthly.rb
44
70
  - lib/recurrence/event/weekly.rb
45
71
  - lib/recurrence/event/yearly.rb
46
- - lib/recurrence/event.rb
47
- - lib/recurrence/shortcuts.rb
48
- - lib/recurrence.rb
72
+ - lib/recurrence/version.rb
73
+ - recurrence.gemspec
74
+ - spec/recurrence_spec.rb
49
75
  has_rdoc: true
50
76
  homepage: http://github.com/fnando/recurrence
51
77
  licenses: []
52
78
 
53
79
  post_install_message:
54
- rdoc_options: []
55
-
80
+ rdoc_options:
81
+ - --charset=UTF-8
56
82
  require_paths:
57
83
  - lib
58
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
59
86
  requirements:
60
87
  - - ">="
61
88
  - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
62
92
  version: "0"
63
- version:
64
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
65
95
  requirements:
66
96
  - - ">="
67
97
  - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
68
101
  version: "0"
69
- version:
70
102
  requirements: []
71
103
 
72
104
  rubyforge_project:
73
- rubygems_version: 1.3.5
105
+ rubygems_version: 1.3.7
74
106
  signing_key:
75
107
  specification_version: 3
76
108
  summary: A simple library to handle recurring events
77
- test_files: []
78
-
109
+ test_files:
110
+ - spec/recurrence_spec.rb
@@ -1,127 +0,0 @@
1
- class Recurrence
2
- module Base
3
- FREQUENCY = %w(day week month year)
4
-
5
- attr_reader :event
6
-
7
- def self.included(base) #:nodoc:
8
- base.extend ClassMethods
9
- end
10
-
11
- # Holds default_until_date configuration.
12
- #
13
- module ClassMethods #:nodoc:
14
- def default_until_date
15
- @default_until_date ||= Date.new(2037, 12, 31)
16
- end
17
-
18
- def default_until_date=(date)
19
- @default_until_date = if date.is_a?(String)
20
- Date.parse(date)
21
- else
22
- date
23
- end
24
- end
25
- end
26
-
27
- def initialize(options)
28
- raise ArgumentError, ':every option is required' unless options.key?(:every)
29
- raise ArgumentError, 'invalid :every option' unless FREQUENCY.include?(options[:every].to_s)
30
-
31
- @options = initialize_dates(options)
32
- @options[:interval] ||= 1
33
-
34
- @event = case @options[:every].to_sym
35
- when :day
36
- Recurrence::Event::Daily.new(@options)
37
- when :week
38
- Recurrence::Event::Weekly.new(@options)
39
- when :month
40
- Recurrence::Event::Monthly.new(@options)
41
- when :year
42
- Recurrence::Event::Yearly.new(@options)
43
- end
44
- end
45
-
46
- def reset!
47
- @event.reset!
48
- @events = nil
49
- end
50
-
51
- def include?(required_date)
52
- required_date = Date.parse(required_date) if required_date.is_a?(String)
53
-
54
- if required_date < @options[:starts] || required_date > @options[:until]
55
- false
56
- else
57
- each do |date|
58
- return true if date == required_date
59
- end
60
- end
61
-
62
- return false
63
- end
64
-
65
- def next
66
- @event.next
67
- end
68
-
69
- def next!
70
- @event.next!
71
- end
72
-
73
- def events(options={})
74
- options[:starts] = Date.parse(options[:starts]) if options[:starts].is_a?(String)
75
- options[:until] = Date.parse(options[:until]) if options[:until].is_a?(String)
76
-
77
- reset! if options[:starts] || options[:until]
78
-
79
- @events ||= begin
80
- _events = []
81
-
82
- loop do
83
- date = @event.next!
84
-
85
- break if date.nil?
86
-
87
- valid_start = options[:starts].nil? || date >= options[:starts]
88
- valid_until = options[:until].nil? || date <= options[:until]
89
- _events << date if valid_start && valid_until
90
-
91
- break if options[:until] && options[:until] <= date
92
- end
93
-
94
- _events
95
- end
96
- end
97
-
98
- def events!(options={})
99
- reset!
100
- events(options)
101
- end
102
-
103
- def each!(&block)
104
- reset!
105
- each(&block)
106
- end
107
-
108
- def each(&block)
109
- events.each do |item|
110
- yield item
111
- end
112
- end
113
-
114
- private
115
-
116
- def initialize_dates(options) #:nodoc:
117
- [:starts, :until].each do |name|
118
- options[name] = Date.parse(options[name]) if options[name].is_a?(String)
119
- end
120
-
121
- options[:starts] ||= Date.today
122
- options[:until] ||= self.class.default_until_date
123
-
124
- options
125
- end
126
- end
127
- end
@@ -1,23 +0,0 @@
1
- class Recurrence
2
- module Shortcuts
3
- def daily(options={})
4
- options[:every] = :day
5
- new(options)
6
- end
7
-
8
- def weekly(options)
9
- options[:every] = :week
10
- new(options)
11
- end
12
-
13
- def monthly(options)
14
- options[:every] = :month
15
- new(options)
16
- end
17
-
18
- def yearly(options)
19
- options[:every] = :year
20
- new(options)
21
- end
22
- end
23
- end