ice_cube 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ice_cube.rb +4 -1
- data/lib/ice_cube/builders/ical_builder.rb +3 -3
- data/lib/ice_cube/builders/string_builder.rb +25 -15
- data/lib/ice_cube/i18n.rb +24 -0
- data/lib/ice_cube/null_i18n.rb +28 -0
- data/lib/ice_cube/schedule.rb +7 -4
- data/lib/ice_cube/validations/count.rb +1 -1
- data/lib/ice_cube/validations/daily_interval.rb +1 -1
- data/lib/ice_cube/validations/day.rb +5 -4
- data/lib/ice_cube/validations/day_of_month.rb +3 -3
- data/lib/ice_cube/validations/day_of_week.rb +7 -2
- data/lib/ice_cube/validations/day_of_year.rb +3 -3
- data/lib/ice_cube/validations/hour_of_day.rb +2 -2
- data/lib/ice_cube/validations/hourly_interval.rb +1 -1
- data/lib/ice_cube/validations/minute_of_hour.rb +2 -2
- data/lib/ice_cube/validations/minutely_interval.rb +1 -1
- data/lib/ice_cube/validations/month_of_year.rb +2 -2
- data/lib/ice_cube/validations/monthly_interval.rb +1 -1
- data/lib/ice_cube/validations/second_of_minute.rb +2 -2
- data/lib/ice_cube/validations/secondly_interval.rb +1 -1
- data/lib/ice_cube/validations/until.rb +2 -1
- data/lib/ice_cube/validations/weekly_interval.rb +1 -1
- data/lib/ice_cube/validations/yearly_interval.rb +1 -1
- data/lib/ice_cube/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39bb12c785e0af4edc922b99cdc1aaabf02cc282
|
4
|
+
data.tar.gz: 4cdf399772a0f10987821ef1f420a62ee1cc3ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38b477ae4371d93de536512ee3917cb9eda9865540a1ba51f240b37ee8819bd3ee1a303fd016583f5df57fe6af9360cf4aaed038a5370f6f1690651b96ed8fc5
|
7
|
+
data.tar.gz: e573e3beaae1f23edb49cca2504e133dad770801fbe14e3e9c13ae7889ce482493597406de846443cd2ed5e78e5b6456550421e8d98c016a21f07c8c5c0af6c1
|
data/lib/ice_cube.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'ice_cube/deprecated'
|
3
|
+
require 'ice_cube/i18n'
|
4
|
+
|
5
|
+
IceCube::I18n.detect_backend!
|
3
6
|
|
4
7
|
module IceCube
|
5
8
|
|
@@ -69,7 +72,7 @@ module IceCube
|
|
69
72
|
# Defines the format used by IceCube when printing out Schedule#to_s.
|
70
73
|
# Defaults to '%B %e, %Y'
|
71
74
|
def self.to_s_time_format
|
72
|
-
|
75
|
+
IceCube::I18n.t("ice_cube.date.formats.default")
|
73
76
|
end
|
74
77
|
|
75
78
|
# Sets the format used by IceCube when printing out Schedule#to_s.
|
@@ -32,15 +32,15 @@ module IceCube
|
|
32
32
|
|
33
33
|
def self.ical_utc_format(time)
|
34
34
|
time = time.dup.utc
|
35
|
-
|
35
|
+
IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ') # utc time
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.ical_format(time, force_utc)
|
39
39
|
time = time.dup.utc if force_utc
|
40
40
|
if time.utc?
|
41
|
-
":#{
|
41
|
+
":#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ')}" # utc time
|
42
42
|
else
|
43
|
-
";TZID=#{
|
43
|
+
";TZID=#{IceCube::I18n.l(time, format: '%Z:%Y%m%dT%H%M%S')}" # local time specified
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -13,14 +13,18 @@ module IceCube
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
@
|
16
|
+
string = @base || ''
|
17
|
+
@types.each do |type, segments|
|
17
18
|
if f = self.class.formatter(type)
|
18
|
-
|
19
|
+
current = f.call(segments)
|
19
20
|
else
|
20
21
|
next if segments.empty?
|
21
|
-
|
22
|
+
current = self.class.sentence(segments)
|
22
23
|
end
|
24
|
+
f = IceCube::I18n.t('ice_cube.string.format')[type] ? type : 'default'
|
25
|
+
string = IceCube::I18n.t("ice_cube.string.format.#{f}", rest: string, current: current)
|
23
26
|
end
|
27
|
+
string
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.formatter(type)
|
@@ -34,27 +38,33 @@ module IceCube
|
|
34
38
|
|
35
39
|
module Helpers
|
36
40
|
|
37
|
-
NUMBER_SUFFIX = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
|
38
|
-
SPECIAL_SUFFIX = { 11 => 'th', 12 => 'th', 13 => 'th', 14 => 'th' }
|
39
|
-
|
40
41
|
# influenced by ActiveSupport's to_sentence
|
41
42
|
def sentence(array)
|
42
43
|
case array.length
|
43
44
|
when 0 ; ''
|
44
45
|
when 1 ; array[0].to_s
|
45
|
-
when 2 ; "#{array[0]}
|
46
|
-
else ; "#{array[0...-1].join('
|
46
|
+
when 2 ; "#{array[0]}#{IceCube::I18n.t('ice_cube.array.two_words_connector')}#{array[1]}"
|
47
|
+
else ; "#{array[0...-1].join(IceCube::I18n.t('ice_cube.array.words_connector'))}#{IceCube::I18n.t('ice_cube.array.last_word_connector')}#{array[-1]}"
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
51
|
def nice_number(number)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
literal_ordinal(number) || ordinalize(number)
|
53
|
+
end
|
54
|
+
|
55
|
+
def ordinalize(number)
|
56
|
+
IceCube::I18n.t('ice_cube.integer.ordinal', number: number, ordinal: ordinal(number))
|
57
|
+
end
|
58
|
+
|
59
|
+
def literal_ordinal(number)
|
60
|
+
IceCube::I18n.t("ice_cube.integer.literal_ordinals")[number]
|
61
|
+
end
|
62
|
+
|
63
|
+
def ordinal(number)
|
64
|
+
ord = IceCube::I18n.t("ice_cube.integer.ordinals")[number] ||
|
65
|
+
IceCube::I18n.t("ice_cube.integer.ordinals")[number % 10] ||
|
66
|
+
IceCube::I18n.t('ice_cube.integer.ordinals')[:default]
|
67
|
+
number >= 0 ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
|
58
68
|
end
|
59
69
|
|
60
70
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module IceCube
|
2
|
+
module I18n
|
3
|
+
def self.t(*args)
|
4
|
+
backend.t(*args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.l(*args)
|
8
|
+
backend.l(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.backend
|
12
|
+
@backend
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.detect_backend!
|
16
|
+
require 'i18n'
|
17
|
+
::I18n.load_path += Dir[File.expand_path('../../../config/locales/*{rb,yml}', __FILE__)]
|
18
|
+
@backend = ::I18n
|
19
|
+
rescue LoadError
|
20
|
+
require 'ice_cube/null_i18n'
|
21
|
+
@backend = NullI18n
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module IceCube
|
4
|
+
module NullI18n
|
5
|
+
def self.t(key, options = {})
|
6
|
+
base = key.to_s.split('.').reduce(config) { |hash, current_key| hash[current_key] }
|
7
|
+
|
8
|
+
base = base[options[:count] == 1 ? "one" : "other"] if options[:count]
|
9
|
+
|
10
|
+
if base.is_a?(Hash)
|
11
|
+
return base.each_with_object({}) do |(key, value), hash|
|
12
|
+
hash[key.is_a?(String) ? key.to_sym : key] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
options.reduce(base) { |result, (find, replace)| result.gsub("%{#{find}}", "#{replace}") }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.l(date_or_time, options = {})
|
20
|
+
return date_or_time.strftime(options[:format]) if options[:format]
|
21
|
+
date_or_time.strftime(t('ice_cube.date.formats.default'))
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config
|
25
|
+
@config ||= YAML.load(File.read(File.join(File.dirname(__FILE__), '..', '..', 'config', 'locales', 'en.yml')))['en']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ice_cube/schedule.rb
CHANGED
@@ -313,11 +313,14 @@ module IceCube
|
|
313
313
|
def to_s
|
314
314
|
pieces = []
|
315
315
|
rd = recurrence_times_with_start_time - extimes
|
316
|
-
pieces.concat rd.sort.map { |t|
|
316
|
+
pieces.concat rd.sort.map { |t| IceCube::I18n.l(t, format: IceCube.to_s_time_format) }
|
317
317
|
pieces.concat rrules.map { |t| t.to_s }
|
318
|
-
pieces.concat exrules.map { |t|
|
319
|
-
pieces.concat extimes.sort.map { |t|
|
320
|
-
|
318
|
+
pieces.concat exrules.map { |t| IceCube::I18n.t('ice_cube.not', target: t.to_s) }
|
319
|
+
pieces.concat extimes.sort.map { |t|
|
320
|
+
target = IceCube::I18n.l(t, format: IceCube.to_s_time_format)
|
321
|
+
IceCube::I18n.t('ice_cube.not_on', target: target)
|
322
|
+
}
|
323
|
+
pieces.join(IceCube::I18n.t('ice_cube.pieces_connector'))
|
321
324
|
end
|
322
325
|
|
323
326
|
# Serialize this schedule to_ical
|
@@ -54,12 +54,13 @@ module IceCube
|
|
54
54
|
validation_days.sort!
|
55
55
|
# pick the right shortening, if applicable
|
56
56
|
if validation_days == [0, 6]
|
57
|
-
'
|
57
|
+
IceCube::I18n.t('ice_cube.on_weekends')
|
58
58
|
elsif validation_days == (1..5).to_a
|
59
|
-
'
|
59
|
+
IceCube::I18n.t('ice_cube.on_weekdays')
|
60
60
|
else
|
61
|
-
|
62
|
-
|
61
|
+
day_names = ->(d){ "#{IceCube::I18n.t("ice_cube.days_on")[d]}" }
|
62
|
+
segments = validation_days.map(&day_names)
|
63
|
+
IceCube::I18n.t('ice_cube.on_days', days: StringBuilder.sentence(segments))
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
@@ -43,9 +43,9 @@ module IceCube
|
|
43
43
|
end
|
44
44
|
|
45
45
|
StringBuilder.register_formatter(:day_of_month) do |entries|
|
46
|
-
|
47
|
-
str
|
48
|
-
str
|
46
|
+
sentence = StringBuilder.sentence(entries)
|
47
|
+
str = IceCube::I18n.t('ice_cube.days_of_month', count: entries.size, segments: sentence)
|
48
|
+
IceCube::I18n.t('ice_cube.on', sentence: str)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -45,7 +45,11 @@ module IceCube
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_s(builder)
|
48
|
-
builder.piece(:day_of_week) <<
|
48
|
+
builder.piece(:day_of_week) << IceCube::I18n.t(
|
49
|
+
'ice_cube.days_of_week',
|
50
|
+
segments: StringBuilder.nice_number(occ),
|
51
|
+
day: IceCube::I18n.t('ice_cube.date.day_names')[day]
|
52
|
+
)
|
49
53
|
end
|
50
54
|
|
51
55
|
def build_hash(builder)
|
@@ -62,7 +66,8 @@ module IceCube
|
|
62
66
|
end
|
63
67
|
|
64
68
|
StringBuilder.register_formatter(:day_of_week) do |segments|
|
65
|
-
|
69
|
+
sentence = segments.join(IceCube::I18n.t('ice_cube.array.two_words_connector'))
|
70
|
+
IceCube::I18n.t('ice_cube.on', sentence: sentence)
|
66
71
|
end
|
67
72
|
|
68
73
|
end
|
@@ -49,9 +49,9 @@ module IceCube
|
|
49
49
|
end
|
50
50
|
|
51
51
|
StringBuilder.register_formatter(:day_of_year) do |entries|
|
52
|
-
str =
|
53
|
-
|
54
|
-
|
52
|
+
str = StringBuilder.sentence(entries)
|
53
|
+
sentence = IceCube::I18n.t('ice_cube.days_of_year', count: entries.size, segments: str)
|
54
|
+
IceCube::I18n.t('ice_cube.on', sentence: sentence)
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -44,8 +44,8 @@ module IceCube
|
|
44
44
|
end
|
45
45
|
|
46
46
|
StringBuilder.register_formatter(:hour_of_day) do |segments|
|
47
|
-
str =
|
48
|
-
|
47
|
+
str = StringBuilder.sentence(segments)
|
48
|
+
IceCube::I18n.t('ice_cube.at_hours_of_the_day', count: segments.size, segments: str)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -43,8 +43,8 @@ module IceCube
|
|
43
43
|
end
|
44
44
|
|
45
45
|
StringBuilder.register_formatter(:minute_of_hour) do |segments|
|
46
|
-
str =
|
47
|
-
|
46
|
+
str = StringBuilder.sentence(segments)
|
47
|
+
IceCube::I18n.t('ice_cube.on_minutes_of_hour', count: segments.size, segments: str)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -32,7 +32,7 @@ module IceCube
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def build_s(builder)
|
35
|
-
builder.piece(:month_of_year) <<
|
35
|
+
builder.piece(:month_of_year) << IceCube::I18n.t("ice_cube.date.month_names")[month]
|
36
36
|
end
|
37
37
|
|
38
38
|
def build_hash(builder)
|
@@ -44,7 +44,7 @@ module IceCube
|
|
44
44
|
end
|
45
45
|
|
46
46
|
StringBuilder.register_formatter(:month_of_year) do |segments|
|
47
|
-
"in
|
47
|
+
IceCube::I18n.t("ice_cube.in", target: StringBuilder.sentence(segments))
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -43,8 +43,8 @@ module IceCube
|
|
43
43
|
end
|
44
44
|
|
45
45
|
StringBuilder.register_formatter(:second_of_minute) do |segments|
|
46
|
-
str =
|
47
|
-
|
46
|
+
str = StringBuilder.sentence(segments)
|
47
|
+
IceCube::I18n.t('ice_cube.on_seconds_of_minute', count: segments.size, segments: str)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -38,7 +38,8 @@ module IceCube
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def build_s(builder)
|
41
|
-
|
41
|
+
date = IceCube::I18n.l(time, format: IceCube.to_s_time_format)
|
42
|
+
builder.piece(:until) << IceCube::I18n.t('ice_cube.until', date: date)
|
42
43
|
end
|
43
44
|
|
44
45
|
def build_hash(builder)
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Crepezzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
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'
|
69
83
|
description: ice_cube is a recurring date library for Ruby. It allows for quick,
|
70
84
|
programatic expansion of recurring date rules.
|
71
85
|
email: john@crepezzi.com
|
@@ -81,6 +95,8 @@ files:
|
|
81
95
|
- lib/ice_cube/errors/count_exceeded.rb
|
82
96
|
- lib/ice_cube/errors/until_exceeded.rb
|
83
97
|
- lib/ice_cube/flexible_hash.rb
|
98
|
+
- lib/ice_cube/i18n.rb
|
99
|
+
- lib/ice_cube/null_i18n.rb
|
84
100
|
- lib/ice_cube/occurrence.rb
|
85
101
|
- lib/ice_cube/parsers/hash_parser.rb
|
86
102
|
- lib/ice_cube/parsers/ical_parser.rb
|
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
version: '0'
|
140
156
|
requirements: []
|
141
157
|
rubyforge_project: ice-cube
|
142
|
-
rubygems_version: 2.4.
|
158
|
+
rubygems_version: 2.4.8
|
143
159
|
signing_key:
|
144
160
|
specification_version: 4
|
145
161
|
summary: Ruby Date Recurrence Library
|