timely 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +6 -0
- data/lib/timely/version.rb +1 -1
- data/lib/timely/week_days.rb +43 -33
- data/timely.gemspec +1 -0
- 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: e269e83cabcd6ebf62cc0e79c35dd7b4c91dc7da
|
4
|
+
data.tar.gz: d4a795800ff6fdf86b2a5d7e3e479f64148172e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4d7a6dc25c00a7ae5db203a787eb1ebfdaa9768cb7283118182dec200621d4bb8660701d6f8a64d9186493237f785e4573f4b1caff234e226aef3653a1da86b
|
7
|
+
data.tar.gz: 9831dec21982816e62f8b301c8ff2c49696c9df083c87c827ebc6b54f9a150e6e5217dd8c9c89616b8c5eca22fb7cde5da50407b2d9bb52bd54a45b527ec8380
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.4
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/timely/version.rb
CHANGED
data/lib/timely/week_days.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Timely
|
2
2
|
class WeekDays
|
3
|
-
WEEKDAY_KEYS = [
|
3
|
+
WEEKDAY_KEYS = %i[sun mon tue wed thu fri sat]
|
4
4
|
|
5
5
|
# Create a new Weekdays object
|
6
6
|
# weekdays can be in three formats
|
@@ -13,20 +13,20 @@ module Timely
|
|
13
13
|
# e.g. [1, 0, 1, 0, 0, 0, 0] is Sunday and Tuesday
|
14
14
|
def initialize(weekdays)
|
15
15
|
@weekdays = {
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
16
|
+
sun: false,
|
17
|
+
mon: false,
|
18
|
+
tue: false,
|
19
|
+
wed: false,
|
20
|
+
thu: false,
|
21
|
+
fri: false,
|
22
|
+
sat: false
|
23
23
|
}
|
24
24
|
|
25
25
|
case weekdays
|
26
|
-
when
|
26
|
+
when Integer
|
27
27
|
# 4 -> 0000100 (binary) -> "0010000" (reversed string) -> {:tue => true}
|
28
28
|
weekdays.to_s(2).reverse.each_char.with_index do |char, index|
|
29
|
-
set_day(index, char ==
|
29
|
+
set_day(index, char == "1")
|
30
30
|
end
|
31
31
|
when Hash
|
32
32
|
weekdays.each_pair do |day, value|
|
@@ -38,16 +38,17 @@ module Timely
|
|
38
38
|
end
|
39
39
|
when NilClass
|
40
40
|
@weekdays = {
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
41
|
+
sun: true,
|
42
|
+
mon: true,
|
43
|
+
tue: true,
|
44
|
+
wed: true,
|
45
|
+
thu: true,
|
46
|
+
fri: true,
|
47
|
+
sat: true
|
48
48
|
}
|
49
49
|
else
|
50
|
-
raise ArgumentError,
|
50
|
+
raise ArgumentError,
|
51
|
+
"You must initialize with an Integer, Hash or Array"
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -61,15 +62,11 @@ module Timely
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def set_day(day, set)
|
64
|
-
key =
|
65
|
-
|
66
|
-
|
67
|
-
day.to_sym
|
68
|
-
else
|
69
|
-
day
|
65
|
+
key = day_to_index(day)
|
66
|
+
unless WEEKDAY_KEYS.include?(key)
|
67
|
+
raise ArgumentError, "Invalid week day index #{key}"
|
70
68
|
end
|
71
|
-
|
72
|
-
@weekdays[key] = [true, 'true', 1, '1'].include?(set)
|
69
|
+
@weekdays[key] = [true, "true", 1, "1"].include?(set)
|
73
70
|
end
|
74
71
|
|
75
72
|
def applies_for_date?(date)
|
@@ -80,33 +77,34 @@ module Timely
|
|
80
77
|
# Accepts either symbol or integer
|
81
78
|
# e.g. :sun or 0 = Sunday, :sat or 6 = Saturday
|
82
79
|
def has_day?(weekday)
|
83
|
-
weekday = WEEKDAY_KEYS[weekday] if weekday.is_a?(
|
80
|
+
weekday = WEEKDAY_KEYS[weekday] if weekday.is_a?(Integer)
|
84
81
|
@weekdays[weekday]
|
85
82
|
end
|
86
83
|
|
87
84
|
def number_of_occurances_in(range)
|
88
85
|
range.inject(0) do |count, date|
|
89
|
-
applies_for_date?(date) ? count+1 : count
|
86
|
+
applies_for_date?(date) ? count + 1 : count
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
90
|
# Returns true if all days are selected
|
94
91
|
def all_days?
|
95
|
-
@weekdays.all?{|
|
92
|
+
@weekdays.all? { |_day, day_selected| day_selected }
|
96
93
|
end
|
97
94
|
|
98
95
|
# Returns array of weekday selected
|
99
96
|
# e.g. [:sun, :sat]
|
100
97
|
def weekdays
|
101
|
-
selected = @weekdays.select{|
|
98
|
+
selected = @weekdays.select { |_day, day_selected| day_selected }
|
102
99
|
# Ruby 1.8 returns an array for Hash#select and loses order
|
103
|
-
|
100
|
+
return selected.keys if selected.is_a?(Hash)
|
101
|
+
selected.map(&:first).sort_by { |v| WEEKDAY_KEYS.index(v) }
|
104
102
|
end
|
105
103
|
|
106
104
|
# Returns comma separated and capitalized in Sun-Sat order
|
107
105
|
# e.g. 'Mon, Tue, Wed' or 'Sat' or 'Sun, Sat'
|
108
106
|
def to_s
|
109
|
-
days = weekdays.map{|day| day.to_s.capitalize}
|
107
|
+
days = weekdays.map { |day| day.to_s.capitalize }
|
110
108
|
last_day = days.pop
|
111
109
|
|
112
110
|
days.empty? ? last_day : days.join(", ") + ", and " + last_day
|
@@ -123,6 +121,18 @@ module Timely
|
|
123
121
|
int
|
124
122
|
end
|
125
123
|
|
126
|
-
|
124
|
+
private
|
125
|
+
|
126
|
+
def day_to_index(day)
|
127
|
+
if day.is_a?(Integer)
|
128
|
+
WEEKDAY_KEYS[day]
|
129
|
+
elsif day.is_a?(String)
|
130
|
+
day.to_sym
|
131
|
+
else
|
132
|
+
day
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
ALL_WEEKDAYS = WeekDays.new(%w[1 1 1 1 1 1 1])
|
127
137
|
end
|
128
138
|
end
|
data/timely.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'coverage-kit'
|
27
27
|
spec.add_development_dependency 'simplecov-rcov'
|
28
28
|
spec.add_development_dependency 'coveralls'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
29
30
|
spec.add_development_dependency 'sqlite3'
|
30
31
|
spec.add_development_dependency 'activesupport'
|
31
32
|
spec.add_development_dependency 'activerecord'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: sqlite3
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,6 +215,8 @@ extra_rdoc_files: []
|
|
201
215
|
files:
|
202
216
|
- ".gitignore"
|
203
217
|
- ".rspec"
|
218
|
+
- ".rubocop.yml"
|
219
|
+
- ".ruby-version"
|
204
220
|
- ".travis.yml"
|
205
221
|
- CHANGELOG.md
|
206
222
|
- Gemfile
|
@@ -280,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
296
|
version: '0'
|
281
297
|
requirements: []
|
282
298
|
rubyforge_project:
|
283
|
-
rubygems_version: 2.
|
299
|
+
rubygems_version: 2.6.14.1
|
284
300
|
signing_key:
|
285
301
|
specification_version: 4
|
286
302
|
summary: Set of time, date, weekday related methods.
|