hiccup 0.5.14 → 0.5.15
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.
- checksums.yaml +4 -4
- data/lib/hiccup.rb +17 -17
- data/lib/hiccup/convenience.rb +9 -9
- data/lib/hiccup/core_ext/date.rb +7 -7
- data/lib/hiccup/core_ext/duration.rb +4 -4
- data/lib/hiccup/core_ext/enumerable.rb +2 -2
- data/lib/hiccup/core_ext/fixnum.rb +2 -2
- data/lib/hiccup/core_ext/hash.rb +2 -2
- data/lib/hiccup/enumerable.rb +43 -29
- data/lib/hiccup/enumerable/annually_enumerator.rb +23 -23
- data/lib/hiccup/enumerable/monthly_date_enumerator.rb +2 -2
- data/lib/hiccup/enumerable/monthly_enumerator.rb +40 -40
- data/lib/hiccup/enumerable/never_enumerator.rb +8 -8
- data/lib/hiccup/enumerable/schedule_enumerator.rb +39 -39
- data/lib/hiccup/enumerable/weekly_enumerator.rb +30 -30
- data/lib/hiccup/errors.rb +4 -0
- data/lib/hiccup/humanizable.rb +19 -19
- data/lib/hiccup/inferable.rb +30 -30
- data/lib/hiccup/inferable/dates_enumerator.rb +6 -6
- data/lib/hiccup/inferable/guesser.rb +21 -21
- data/lib/hiccup/inferable/score.rb +7 -7
- data/lib/hiccup/inferable/scorer.rb +19 -19
- data/lib/hiccup/schedule.rb +10 -10
- data/lib/hiccup/serializable/ical.rb +13 -13
- data/lib/hiccup/serializers/ical.rb +59 -59
- data/lib/hiccup/validatable.rb +23 -23
- data/lib/hiccup/version.rb +1 -1
- data/test/core_ext_date_test.rb +5 -5
- data/test/duration_ext_test.rb +8 -8
- data/test/enumerable_test.rb +103 -103
- data/test/humanizable_test.rb +24 -24
- data/test/ical_serializable_test.rb +29 -29
- data/test/inferrable_test.rb +84 -84
- data/test/leap_year_test.rb +7 -7
- data/test/monthly_enumerator_test.rb +13 -13
- data/test/performance_test.rb +7 -7
- data/test/validatable_test.rb +1 -1
- data/test/weekly_enumerator_test.rb +38 -38
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180b4da041c8d42e737e95f8d2960f810d499880
|
4
|
+
data.tar.gz: 749a34b97e947982cb47f3623b34b9953368b5a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce0d249305f1740a3f01eae8397591c54872f7eb91b82a7696bb6546f0e7dff76f42c925ea0b7d8504ff6660b5f791dcdc49ed9f9108fb0ede15ad0f59be94b
|
7
|
+
data.tar.gz: cbe05cd9de92f19f785300905c17c19c55aec7c0700d09fc6282df45963f0d1b1f217d934d982fe879106c15dce77b4e09f2810ea099ac6b4e36cd3c4a5af787
|
data/lib/hiccup.rb
CHANGED
@@ -22,7 +22,7 @@ require "hiccup/version"
|
|
22
22
|
# monthly recurrence
|
23
23
|
#
|
24
24
|
# Examples:
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# Every other Monday
|
27
27
|
# :kind => :weekly, :weekly_pattern => ["Monday"]
|
28
28
|
#
|
@@ -34,45 +34,45 @@ require "hiccup/version"
|
|
34
34
|
#
|
35
35
|
#
|
36
36
|
module Hiccup
|
37
|
-
|
38
|
-
|
37
|
+
|
38
|
+
|
39
39
|
Kinds = [:never, :weekly, :monthly, :annually]
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
def hiccup(*modules)
|
43
43
|
options = modules.extract_options!
|
44
44
|
add_hiccup_modules(modules)
|
45
45
|
add_hiccup_serialization_formats(options[:serializable])
|
46
46
|
end
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
|
49
49
|
private
|
50
|
-
|
51
|
-
|
50
|
+
|
51
|
+
|
52
52
|
def add_hiccup_modules(modules)
|
53
53
|
(modules||[]).each {|name| add_hiccup_module(name)}
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def add_hiccup_module(symbol)
|
57
57
|
include_hiccup_module "hiccup/#{symbol}"
|
58
58
|
end
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
|
61
61
|
def add_hiccup_serialization_formats(formats)
|
62
62
|
(formats||[]).each {|format| add_hiccup_serialization_format(format)}
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def add_hiccup_serialization_format(format)
|
66
66
|
include_hiccup_module "hiccup/serializable/#{format}"
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
def include_hiccup_module(module_path)
|
71
71
|
require module_path
|
72
72
|
include module_path.classify.constantize
|
73
73
|
end
|
74
|
-
|
75
|
-
|
74
|
+
|
75
|
+
|
76
76
|
end
|
77
77
|
|
78
78
|
|
data/lib/hiccup/convenience.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
module Hiccup
|
2
2
|
module Convenience
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
|
5
5
|
def never?
|
6
6
|
kind == :never
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def weekly?
|
10
10
|
kind == :weekly
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def monthly?
|
14
14
|
kind == :monthly
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def annually?
|
18
18
|
kind == :annually
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
|
22
22
|
def ends?
|
23
23
|
return %w{true 1 t}.member?(ends) if ends.is_a?(String)
|
24
24
|
!!ends
|
25
25
|
end
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
|
28
28
|
end
|
29
29
|
end
|
data/lib/hiccup/core_ext/date.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Hiccup
|
2
2
|
module CoreExtensions
|
3
3
|
module Date
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
|
6
|
+
|
7
7
|
def get_nth_wday_of_month
|
8
8
|
(day - 1) / 7 + 1
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def get_nth_wday_string
|
12
12
|
"#{get_nth_wday_of_month} #{::Date::DAYNAMES[wday]}"
|
13
13
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -4,19 +4,19 @@ require "active_support/duration"
|
|
4
4
|
module Hiccup
|
5
5
|
module CoreExt
|
6
6
|
module DurationExtensions
|
7
|
-
|
7
|
+
|
8
8
|
def from(*args)
|
9
9
|
since(*args)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def after(*args)
|
13
13
|
since(*args)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def before(*args)
|
17
17
|
ago(*args)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Hiccup
|
2
2
|
module CoreExt
|
3
3
|
module EnumerableExtensions
|
4
|
-
|
4
|
+
|
5
5
|
def to_histogram
|
6
6
|
self.each_with_object(Hash.new { 0 }) do |item, histogram|
|
7
7
|
pattern = block_given? ? yield(item) : item
|
8
8
|
histogram[pattern] += 1
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/hiccup/core_ext/hash.rb
CHANGED
data/lib/hiccup/enumerable.rb
CHANGED
@@ -3,19 +3,33 @@ require "hiccup/enumerable/annually_enumerator"
|
|
3
3
|
require "hiccup/enumerable/monthly_enumerator"
|
4
4
|
require "hiccup/enumerable/never_enumerator"
|
5
5
|
require "hiccup/enumerable/weekly_enumerator"
|
6
|
+
require "hiccup/errors"
|
6
7
|
|
7
8
|
|
8
9
|
module Hiccup
|
9
10
|
module Enumerable
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
|
13
|
+
|
13
14
|
def enumerator
|
14
15
|
ScheduleEnumerator.enum_for(self)
|
15
16
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def to_a
|
21
|
+
raise UnboundedEnumerationError, "This schedule does not have an end date and so cannot be asked to list all of its dates, ever" unless ends?
|
22
|
+
|
23
|
+
occurrences = []
|
24
|
+
enum = enumerator.new(self, start_date)
|
25
|
+
while occurrence = enum.next
|
26
|
+
occurrences << occurrence
|
27
|
+
end
|
28
|
+
occurrences
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
19
33
|
def occurrences_between(earlier_date, later_date)
|
20
34
|
occurrences = []
|
21
35
|
enum = enumerator.new(self, earlier_date)
|
@@ -24,30 +38,30 @@ module Hiccup
|
|
24
38
|
end
|
25
39
|
occurrences
|
26
40
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
41
|
+
|
42
|
+
|
43
|
+
|
30
44
|
def first_occurrence_on_or_after(date)
|
31
45
|
enumerator.new(self, date).next
|
32
46
|
end
|
33
|
-
|
47
|
+
|
34
48
|
def first_occurrence_after(date)
|
35
49
|
first_occurrence_on_or_after(date.to_date + 1)
|
36
50
|
end
|
37
51
|
alias :next_occurrence_after :first_occurrence_after
|
38
|
-
|
39
|
-
|
40
|
-
|
52
|
+
|
53
|
+
|
54
|
+
|
41
55
|
def first_occurrence_on_or_before(date)
|
42
56
|
enumerator.new(self, date).prev
|
43
57
|
end
|
44
|
-
|
58
|
+
|
45
59
|
def first_occurrence_before(date)
|
46
60
|
first_occurrence_on_or_before(date.to_date - 1)
|
47
61
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
62
|
+
|
63
|
+
|
64
|
+
|
51
65
|
def occurs_on(date)
|
52
66
|
date = date.to_date
|
53
67
|
date == first_occurrence_on_or_after(date)
|
@@ -56,13 +70,13 @@ module Hiccup
|
|
56
70
|
alias :includes? :occurs_on
|
57
71
|
alias :member? :occurs_on
|
58
72
|
alias :predicts? :occurs_on
|
59
|
-
|
60
|
-
|
61
|
-
|
73
|
+
|
74
|
+
|
75
|
+
|
62
76
|
def n_occurrences_before(limit, date, options={})
|
63
77
|
n_occurrences_on_or_before(limit, date.to_date - 1, options)
|
64
78
|
end
|
65
|
-
|
79
|
+
|
66
80
|
def n_occurrences_on_or_before(limit, date, options={})
|
67
81
|
exceptions = options.fetch(:except, [])
|
68
82
|
occurrences = []
|
@@ -72,17 +86,17 @@ module Hiccup
|
|
72
86
|
end
|
73
87
|
occurrences
|
74
88
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
89
|
+
|
90
|
+
|
91
|
+
|
78
92
|
def first_n_occurrences(limit, options={})
|
79
93
|
n_occurrences_on_or_after(limit, start_date, options)
|
80
94
|
end
|
81
|
-
|
95
|
+
|
82
96
|
def n_occurrences_after(limit, date, options={})
|
83
97
|
n_occurrences_on_or_after(limit, date.to_date + 1, options)
|
84
98
|
end
|
85
|
-
|
99
|
+
|
86
100
|
def n_occurrences_on_or_after(limit, date, options={})
|
87
101
|
exceptions = options.fetch(:except, [])
|
88
102
|
occurrences = []
|
@@ -92,8 +106,8 @@ module Hiccup
|
|
92
106
|
end
|
93
107
|
occurrences
|
94
108
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
|
110
|
+
|
111
|
+
|
98
112
|
end
|
99
113
|
end
|
@@ -3,74 +3,74 @@ require 'hiccup/enumerable/schedule_enumerator'
|
|
3
3
|
module Hiccup
|
4
4
|
module Enumerable
|
5
5
|
class AnnuallyEnumerator < ScheduleEnumerator
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(*args)
|
8
8
|
super
|
9
9
|
@month, @day = start_date.month, start_date.day
|
10
|
-
|
10
|
+
|
11
11
|
if month == 2 and day == 29
|
12
12
|
def self.current_date
|
13
13
|
Date.new(year, 2, leap_year?(year) ? 29 : 28)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
attr_reader :month, :day
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
attr_reader :year
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
|
24
|
+
|
25
|
+
|
26
26
|
def advance!
|
27
27
|
@year += skip
|
28
28
|
current_date
|
29
29
|
rescue
|
30
30
|
advance!
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def rewind!
|
34
34
|
@year -= skip
|
35
35
|
current_date
|
36
36
|
rescue
|
37
37
|
rewind!
|
38
38
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
|
40
|
+
|
41
|
+
|
42
42
|
def first_occurrence_on_or_after(date)
|
43
43
|
@year = date.year
|
44
44
|
@year += 1 if (date.month > month) or (date.month == month and date.day > day)
|
45
|
-
|
45
|
+
|
46
46
|
remainder = (@year - start_date.year) % skip
|
47
47
|
@year += (skip - remainder) if remainder > 0
|
48
|
-
|
48
|
+
|
49
49
|
current_date
|
50
50
|
rescue
|
51
51
|
advance!
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def first_occurrence_on_or_before(date)
|
55
55
|
@year = date.year
|
56
56
|
@year -= 1 if (date.month < month) or (date.month == month and date.day < day)
|
57
|
-
|
57
|
+
|
58
58
|
remainder = (@year - start_date.year) % skip
|
59
59
|
@year -= remainder if remainder > 0
|
60
|
-
|
60
|
+
|
61
61
|
current_date
|
62
62
|
rescue
|
63
63
|
rewind!
|
64
64
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
|
66
|
+
|
67
|
+
|
68
68
|
def current_date
|
69
69
|
Date.new(year, month, day)
|
70
70
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
|
72
|
+
|
73
|
+
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|