ice_cube_chosko 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/config/locales/en.yml +178 -0
  3. data/config/locales/es.yml +176 -0
  4. data/config/locales/ja.yml +107 -0
  5. data/lib/ice_cube.rb +92 -0
  6. data/lib/ice_cube/builders/hash_builder.rb +27 -0
  7. data/lib/ice_cube/builders/ical_builder.rb +59 -0
  8. data/lib/ice_cube/builders/string_builder.rb +76 -0
  9. data/lib/ice_cube/deprecated.rb +36 -0
  10. data/lib/ice_cube/errors/count_exceeded.rb +7 -0
  11. data/lib/ice_cube/errors/until_exceeded.rb +7 -0
  12. data/lib/ice_cube/flexible_hash.rb +40 -0
  13. data/lib/ice_cube/i18n.rb +24 -0
  14. data/lib/ice_cube/null_i18n.rb +28 -0
  15. data/lib/ice_cube/occurrence.rb +101 -0
  16. data/lib/ice_cube/parsers/hash_parser.rb +91 -0
  17. data/lib/ice_cube/parsers/ical_parser.rb +91 -0
  18. data/lib/ice_cube/parsers/yaml_parser.rb +19 -0
  19. data/lib/ice_cube/rule.rb +123 -0
  20. data/lib/ice_cube/rules/daily_rule.rb +16 -0
  21. data/lib/ice_cube/rules/hourly_rule.rb +16 -0
  22. data/lib/ice_cube/rules/minutely_rule.rb +16 -0
  23. data/lib/ice_cube/rules/monthly_rule.rb +16 -0
  24. data/lib/ice_cube/rules/secondly_rule.rb +15 -0
  25. data/lib/ice_cube/rules/weekly_rule.rb +16 -0
  26. data/lib/ice_cube/rules/yearly_rule.rb +16 -0
  27. data/lib/ice_cube/schedule.rb +529 -0
  28. data/lib/ice_cube/single_occurrence_rule.rb +28 -0
  29. data/lib/ice_cube/time_util.rb +328 -0
  30. data/lib/ice_cube/validated_rule.rb +184 -0
  31. data/lib/ice_cube/validations/count.rb +61 -0
  32. data/lib/ice_cube/validations/daily_interval.rb +54 -0
  33. data/lib/ice_cube/validations/day.rb +71 -0
  34. data/lib/ice_cube/validations/day_of_month.rb +55 -0
  35. data/lib/ice_cube/validations/day_of_week.rb +77 -0
  36. data/lib/ice_cube/validations/day_of_year.rb +61 -0
  37. data/lib/ice_cube/validations/fixed_value.rb +95 -0
  38. data/lib/ice_cube/validations/hour_of_day.rb +55 -0
  39. data/lib/ice_cube/validations/hourly_interval.rb +54 -0
  40. data/lib/ice_cube/validations/lock.rb +95 -0
  41. data/lib/ice_cube/validations/minute_of_hour.rb +54 -0
  42. data/lib/ice_cube/validations/minutely_interval.rb +54 -0
  43. data/lib/ice_cube/validations/month_of_year.rb +54 -0
  44. data/lib/ice_cube/validations/monthly_interval.rb +53 -0
  45. data/lib/ice_cube/validations/schedule_lock.rb +46 -0
  46. data/lib/ice_cube/validations/second_of_minute.rb +54 -0
  47. data/lib/ice_cube/validations/secondly_interval.rb +51 -0
  48. data/lib/ice_cube/validations/until.rb +57 -0
  49. data/lib/ice_cube/validations/weekly_interval.rb +67 -0
  50. data/lib/ice_cube/validations/yearly_interval.rb +53 -0
  51. data/lib/ice_cube/version.rb +5 -0
  52. data/spec/spec_helper.rb +64 -0
  53. metadata +166 -0
@@ -0,0 +1,54 @@
1
+ module IceCube
2
+
3
+ module Validations::SecondOfMinute
4
+
5
+ def second_of_minute(*seconds)
6
+ seconds.flatten.each do |second|
7
+ unless second.is_a?(Fixnum)
8
+ raise ArgumentError, "Expecting Fixnum value for second, got #{second.inspect}"
9
+ end
10
+ validations_for(:second_of_minute) << Validation.new(second)
11
+ end
12
+ clobber_base_validations :sec
13
+ self
14
+ end
15
+
16
+ class Validation < Validations::FixedValue
17
+
18
+ attr_reader :second
19
+ alias :value :second
20
+
21
+ def initialize(second)
22
+ @second = second
23
+ end
24
+
25
+ def type
26
+ :sec
27
+ end
28
+
29
+ def dst_adjust?
30
+ false
31
+ end
32
+
33
+ def build_s(builder)
34
+ builder.piece(:second_of_minute) << StringBuilder.nice_number(second)
35
+ end
36
+
37
+ def build_hash(builder)
38
+ builder.validations_array(:second_of_minute) << second
39
+ end
40
+
41
+ def build_ical(builder)
42
+ builder['BYSECOND'] << second
43
+ end
44
+
45
+ StringBuilder.register_formatter(:second_of_minute) do |segments|
46
+ str = StringBuilder.sentence(segments)
47
+ IceCube::I18n.t('ice_cube.on_seconds_of_minute', count: segments.size, segments: str)
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,51 @@
1
+ module IceCube
2
+
3
+ module Validations::SecondlyInterval
4
+
5
+ def interval(interval)
6
+ @interval = normalized_interval(interval)
7
+ replace_validations_for(:interval, [Validation.new(@interval)])
8
+ clobber_base_validations(:sec)
9
+ self
10
+ end
11
+
12
+ class Validation
13
+
14
+ attr_reader :interval
15
+
16
+ def initialize(interval)
17
+ @interval = interval
18
+ end
19
+
20
+ def type
21
+ :sec
22
+ end
23
+
24
+ def dst_adjust?
25
+ false
26
+ end
27
+
28
+ def validate(step_time, schedule)
29
+ seconds = step_time.to_i - schedule.start_time.to_i
30
+ offset = (seconds % interval).nonzero?
31
+ interval - offset if offset
32
+ end
33
+
34
+ def build_s(builder)
35
+ builder.base = IceCube::I18n.t("ice_cube.each_second", count: interval)
36
+ end
37
+
38
+ def build_hash(builder)
39
+ builder[:interval] = interval
40
+ end
41
+
42
+ def build_ical(builder)
43
+ builder['FREQ'] << 'SECONDLY'
44
+ builder['INTERVAL'] << interval unless interval == 1
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,57 @@
1
+ module IceCube
2
+
3
+ module Validations::Until
4
+
5
+ extend Deprecated
6
+
7
+ # Value reader for limit
8
+ def until_time
9
+ @until
10
+ end
11
+ deprecated_alias :until_date, :until_time
12
+
13
+ def until(time)
14
+ time = TimeUtil.ensure_time(time, true)
15
+ @until = time
16
+ replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
17
+ self
18
+ end
19
+
20
+ class Validation
21
+
22
+ attr_reader :time
23
+
24
+ def initialize(time)
25
+ @time = time
26
+ end
27
+
28
+ def type
29
+ :limit
30
+ end
31
+
32
+ def dst_adjust?
33
+ false
34
+ end
35
+
36
+ def validate(step_time, schedule)
37
+ raise UntilExceeded if step_time > time
38
+ end
39
+
40
+ def build_s(builder)
41
+ date = IceCube::I18n.l(time, format: IceCube.to_s_time_format)
42
+ builder.piece(:until) << IceCube::I18n.t('ice_cube.until', date: date)
43
+ end
44
+
45
+ def build_hash(builder)
46
+ builder[:until] = TimeUtil.serialize_time(time)
47
+ end
48
+
49
+ def build_ical(builder)
50
+ builder['UNTIL'] << IcalBuilder.ical_utc_format(time)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,67 @@
1
+ require 'date'
2
+
3
+ module IceCube
4
+
5
+ module Validations::WeeklyInterval
6
+
7
+ def interval(interval, week_start = :sunday)
8
+ @interval = normalized_interval(interval)
9
+ @week_start = TimeUtil.wday_to_sym(week_start)
10
+ replace_validations_for(:interval, [Validation.new(@interval, week_start)])
11
+ clobber_base_validations(:day)
12
+ self
13
+ end
14
+
15
+ def week_start
16
+ @week_start
17
+ end
18
+
19
+ class Validation
20
+
21
+ attr_reader :interval, :week_start
22
+
23
+ def initialize(interval, week_start)
24
+ @interval = interval
25
+ @week_start = week_start
26
+ end
27
+
28
+ def type
29
+ :day
30
+ end
31
+
32
+ def dst_adjust?
33
+ true
34
+ end
35
+
36
+ def validate(step_time, schedule)
37
+ t0, t1 = schedule.start_time, step_time
38
+ d0 = Date.new(t0.year, t0.month, t0.day)
39
+ d1 = Date.new(t1.year, t1.month, t1.day)
40
+ days = (d1 - TimeUtil.normalize_wday(d1.wday, week_start)) -
41
+ (d0 - TimeUtil.normalize_wday(d0.wday, week_start))
42
+ offset = ((days.to_i / 7) % interval).nonzero?
43
+ (interval - offset) * 7 if offset
44
+ end
45
+
46
+ def build_s(builder)
47
+ builder.base = IceCube::I18n.t('ice_cube.each_week', count: interval)
48
+ end
49
+
50
+ def build_hash(builder)
51
+ builder[:interval] = interval
52
+ builder[:week_start] = TimeUtil.sym_to_wday(week_start)
53
+ end
54
+
55
+ def build_ical(builder)
56
+ builder['FREQ'] << 'WEEKLY'
57
+ unless interval == 1
58
+ builder['INTERVAL'] << interval
59
+ builder['WKST'] << week_start.to_s.upcase[0..1]
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,53 @@
1
+ module IceCube
2
+
3
+ module Validations::YearlyInterval
4
+
5
+ def interval(interval)
6
+ @interval = normalized_interval(interval)
7
+ replace_validations_for(:interval, [Validation.new(@interval)])
8
+ clobber_base_validations(:year)
9
+ self
10
+ end
11
+
12
+ class Validation
13
+
14
+ attr_reader :interval
15
+
16
+ def initialize(interval)
17
+ @interval = interval
18
+ end
19
+
20
+ def type
21
+ :year
22
+ end
23
+
24
+ def dst_adjust?
25
+ true
26
+ end
27
+
28
+ def validate(step_time, schedule)
29
+ years = step_time.year - schedule.start_time.year
30
+ offset = (years % interval).nonzero?
31
+ interval - offset if offset
32
+ end
33
+
34
+ def build_s(builder)
35
+ builder.base = IceCube::I18n.t('ice_cube.each_year', count: interval)
36
+ end
37
+
38
+ def build_hash(builder)
39
+ builder[:interval] = interval
40
+ end
41
+
42
+ def build_ical(builder)
43
+ builder['FREQ'] << 'YEARLY'
44
+ unless interval == 1
45
+ builder['INTERVAL'] << interval
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,5 @@
1
+ module IceCube
2
+
3
+ VERSION = '0.1.0'
4
+
5
+ end
@@ -0,0 +1,64 @@
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ rescue LoadError
5
+ # okay
6
+ end
7
+
8
+ require File.dirname(__FILE__) + '/../lib/ice_cube'
9
+
10
+ IceCube.compatibility = 12
11
+
12
+ DAY = Time.utc(2010, 3, 1)
13
+ WEDNESDAY = Time.utc(2010, 6, 23, 5, 0, 0)
14
+
15
+ WORLD_TIME_ZONES = [
16
+ 'America/Anchorage', # -1000 / -0900
17
+ 'Europe/London', # +0000 / +0100
18
+ 'Pacific/Auckland', # +1200 / +1300
19
+ ]
20
+
21
+ RSpec.configure do |config|
22
+ Dir[File.dirname(__FILE__) + '/support/**/*'].each { |f| require f }
23
+
24
+ config.include WarningHelpers
25
+
26
+ config.around :each, :if_active_support_time => true do |example|
27
+ example.run if defined? ActiveSupport
28
+ end
29
+
30
+ config.around :each, :if_active_support_time => false do |example|
31
+ unless defined? ActiveSupport
32
+ stubbed_active_support = ::ActiveSupport = Module.new
33
+ example.run
34
+ Object.send :remove_const, :ActiveSupport
35
+ end
36
+ end
37
+
38
+ config.around :each do |example|
39
+ if zone = example.metadata[:system_time_zone]
40
+ @orig_zone = ENV['TZ']
41
+ ENV['TZ'] = zone
42
+ example.run
43
+ ENV['TZ'] = @orig_zone
44
+ else
45
+ example.run
46
+ end
47
+ end
48
+
49
+ config.before :each do
50
+ if time_args = @example.metadata[:system_time]
51
+ case time_args
52
+ when Array then Time.stub!(:now).and_return Time.local(*time_args)
53
+ when Time then Time.stub!(:now).and_return time_args
54
+ end
55
+ end
56
+ end
57
+
58
+ config.around :each, expect_warnings: true do |example|
59
+ capture_warnings do
60
+ example.run
61
+ end
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ice_cube_chosko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Crepezzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: tzinfo
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ice_cube is a recurring date library for Ruby. It allows for quick,
84
+ programatic expansion of recurring date rules.
85
+ email: john@crepezzi.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - config/locales/en.yml
91
+ - config/locales/es.yml
92
+ - config/locales/ja.yml
93
+ - lib/ice_cube.rb
94
+ - lib/ice_cube/builders/hash_builder.rb
95
+ - lib/ice_cube/builders/ical_builder.rb
96
+ - lib/ice_cube/builders/string_builder.rb
97
+ - lib/ice_cube/deprecated.rb
98
+ - lib/ice_cube/errors/count_exceeded.rb
99
+ - lib/ice_cube/errors/until_exceeded.rb
100
+ - lib/ice_cube/flexible_hash.rb
101
+ - lib/ice_cube/i18n.rb
102
+ - lib/ice_cube/null_i18n.rb
103
+ - lib/ice_cube/occurrence.rb
104
+ - lib/ice_cube/parsers/hash_parser.rb
105
+ - lib/ice_cube/parsers/ical_parser.rb
106
+ - lib/ice_cube/parsers/yaml_parser.rb
107
+ - lib/ice_cube/rule.rb
108
+ - lib/ice_cube/rules/daily_rule.rb
109
+ - lib/ice_cube/rules/hourly_rule.rb
110
+ - lib/ice_cube/rules/minutely_rule.rb
111
+ - lib/ice_cube/rules/monthly_rule.rb
112
+ - lib/ice_cube/rules/secondly_rule.rb
113
+ - lib/ice_cube/rules/weekly_rule.rb
114
+ - lib/ice_cube/rules/yearly_rule.rb
115
+ - lib/ice_cube/schedule.rb
116
+ - lib/ice_cube/single_occurrence_rule.rb
117
+ - lib/ice_cube/time_util.rb
118
+ - lib/ice_cube/validated_rule.rb
119
+ - lib/ice_cube/validations/count.rb
120
+ - lib/ice_cube/validations/daily_interval.rb
121
+ - lib/ice_cube/validations/day.rb
122
+ - lib/ice_cube/validations/day_of_month.rb
123
+ - lib/ice_cube/validations/day_of_week.rb
124
+ - lib/ice_cube/validations/day_of_year.rb
125
+ - lib/ice_cube/validations/fixed_value.rb
126
+ - lib/ice_cube/validations/hour_of_day.rb
127
+ - lib/ice_cube/validations/hourly_interval.rb
128
+ - lib/ice_cube/validations/lock.rb
129
+ - lib/ice_cube/validations/minute_of_hour.rb
130
+ - lib/ice_cube/validations/minutely_interval.rb
131
+ - lib/ice_cube/validations/month_of_year.rb
132
+ - lib/ice_cube/validations/monthly_interval.rb
133
+ - lib/ice_cube/validations/schedule_lock.rb
134
+ - lib/ice_cube/validations/second_of_minute.rb
135
+ - lib/ice_cube/validations/secondly_interval.rb
136
+ - lib/ice_cube/validations/until.rb
137
+ - lib/ice_cube/validations/weekly_interval.rb
138
+ - lib/ice_cube/validations/yearly_interval.rb
139
+ - lib/ice_cube/version.rb
140
+ - spec/spec_helper.rb
141
+ homepage: https://github.com/chosko/ice_cube
142
+ licenses:
143
+ - MIT
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project: ice-cube
161
+ rubygems_version: 2.5.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Ruby Date Recurrence Library
165
+ test_files:
166
+ - spec/spec_helper.rb