doodle 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/examples/example-01.rdoc +16 -0
- data/examples/example-02.rdoc +62 -0
- metadata +3 -1
data/ChangeLog
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'doodle'
|
3
|
+
|
4
|
+
class DateRange < Doodle::Base
|
5
|
+
has :start_date do
|
6
|
+
default { Date.today }
|
7
|
+
end
|
8
|
+
has :end_date do
|
9
|
+
default { start_date }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
dr = DateRange.new
|
14
|
+
dr.start_date # => #<Date: 4909053/2,0,2299161>
|
15
|
+
dr.end_date # => #<Date: 4909053/2,0,2299161>
|
16
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'doodle'
|
3
|
+
|
4
|
+
class DateRange < Doodle::Base
|
5
|
+
has :start_date, :kind => Date do
|
6
|
+
default { Date.today }
|
7
|
+
from String do |s|
|
8
|
+
Date.parse(s)
|
9
|
+
end
|
10
|
+
must "be >= 2000-01-01" do |d|
|
11
|
+
d >= Date.parse('2000-01-01')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
has :end_date do
|
15
|
+
default { start_date }
|
16
|
+
from String do |s|
|
17
|
+
Date.parse(s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
must 'have end_date >= start_date' do
|
21
|
+
end_date >= start_date
|
22
|
+
end
|
23
|
+
from String do |s|
|
24
|
+
m = /(\d{4}-\d{2}-\d{2})\s*(?:to|-|\s)\s*(\d{4}-\d{2}-\d{2})/.match(s)
|
25
|
+
if m
|
26
|
+
self.new(*m.captures)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
dr = DateRange.new '2007-12-31', '2008-01-01'
|
32
|
+
dr.start_date # => #<Date: 4908931/2,0,2299161>
|
33
|
+
dr.end_date # => #<Date: 4908933/2,0,2299161>
|
34
|
+
|
35
|
+
dr = DateRange '2007-12-31', '2008-01-01'
|
36
|
+
dr.start_date # => #<Date: 4908931/2,0,2299161>
|
37
|
+
dr.end_date # => #<Date: 4908933/2,0,2299161>
|
38
|
+
|
39
|
+
dr = DateRange :start_date => '2007-12-31', :end_date => '2008-01-01'
|
40
|
+
dr.start_date # => #<Date: 4908931/2,0,2299161>
|
41
|
+
dr.end_date # => #<Date: 4908933/2,0,2299161>
|
42
|
+
|
43
|
+
dr = DateRange do
|
44
|
+
start_date '2007-12-31'
|
45
|
+
end_date '2008-01-01'
|
46
|
+
end
|
47
|
+
dr.start_date # => #<Date: 4908931/2,0,2299161>
|
48
|
+
dr.end_date # => #<Date: 4908933/2,0,2299161>
|
49
|
+
|
50
|
+
|
51
|
+
dr = DateRange.from '2007-01-01 to 2008-12-31'
|
52
|
+
dr.start_date # => #<Date: 4908203/2,0,2299161>
|
53
|
+
dr.end_date # => #<Date: 4909663/2,0,2299161>
|
54
|
+
|
55
|
+
dr = DateRange.from '2007-01-01 2007-12-31'
|
56
|
+
dr.start_date # => #<Date: 4908203/2,0,2299161>
|
57
|
+
dr.end_date # => #<Date: 4908931/2,0,2299161>
|
58
|
+
|
59
|
+
dr = DateRange '2008-01-01', '2007-12-31'
|
60
|
+
dr.start_date # =>
|
61
|
+
dr.end_date # =>
|
62
|
+
# ~> -:59: #<DateRange:0x747fc @start_date=#<Date: 4908933/2,0,2299161>, @end_date=#<Date: 4908931/2,0,2299161>> must have end_date >= start_date (Doodle::ValidationError)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doodle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -31,7 +31,9 @@ files:
|
|
31
31
|
- examples/event1.rb
|
32
32
|
- examples/event2.rb
|
33
33
|
- examples/example-01.rb
|
34
|
+
- examples/example-01.rdoc
|
34
35
|
- examples/example-02.rb
|
36
|
+
- examples/example-02.rdoc
|
35
37
|
- README
|
36
38
|
- COPYING
|
37
39
|
- ChangeLog
|