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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 584fc428f9daeae0837d23072b66f7f9b243ff64
4
- data.tar.gz: 5fb6844cfb6c8d57bd31993de1ad1d61c6bb3359
3
+ metadata.gz: e269e83cabcd6ebf62cc0e79c35dd7b4c91dc7da
4
+ data.tar.gz: d4a795800ff6fdf86b2a5d7e3e479f64148172e4
5
5
  SHA512:
6
- metadata.gz: 09ba7d44b3b223dd336a0bfc80bf3ea265c9ae9f23d69184ce0844640cd1c26068846123908688e4f6dcd701b47437eb6e398d38d76bd41d940832a9d358e573
7
- data.tar.gz: 5782e3428094d1272eb40a0923394a24c8196099601430374ccacf86fa59fa6b91606e4818938ba7f8f25bebf7a7ec45b8024938eedea19ea349cae0923cc95c
6
+ metadata.gz: c4d7a6dc25c00a7ae5db203a787eb1ebfdaa9768cb7283118182dec200621d4bb8660701d6f8a64d9186493237f785e4573f4b1caff234e226aef3653a1da86b
7
+ data.tar.gz: 9831dec21982816e62f8b301c8ff2c49696c9df083c87c827ebc6b54f9a150e6e5217dd8c9c89616b8c5eca22fb7cde5da50407b2d9bb52bd54a45b527ec8380
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Metrics/LineLength:
2
+ Max: 80
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false # Using Ruby 2.4 doesn't need it
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.4
data/.travis.yml CHANGED
@@ -2,6 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
4
  - 2.3.0
5
+ - 2.4
6
+ matrix:
7
+ fast_finish: true
8
+ exclude:
9
+ - rvm: 2.4
10
+ gemfile: gemfiles/rails3.gemfile
5
11
  script: bundle exec rake spec
6
12
  gemfile:
7
13
  - gemfiles/rails3.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.3.1
6
+
7
+ * Using Fixnum is deprecated
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  * Add time zone awareness for Time#on (e.g. Rails)
@@ -1,3 +1,3 @@
1
1
  module Timely
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module Timely
2
2
  class WeekDays
3
- WEEKDAY_KEYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
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
- :sun => false,
17
- :mon => false,
18
- :tue => false,
19
- :wed => false,
20
- :thu => false,
21
- :fri => false,
22
- :sat => false
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 Fixnum
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 == '1')
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
- :sun => true,
42
- :mon => true,
43
- :tue => true,
44
- :wed => true,
45
- :thu => true,
46
- :fri => true,
47
- :sat => true
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, "You must initialize with an Fixnum, Hash or Array"
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 = if day.is_a?(Fixnum)
65
- WEEKDAY_KEYS[day]
66
- elsif day.is_a?(String)
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
- raise ArgumentError, "Invalid week day index #{key}" unless WEEKDAY_KEYS.include?(key)
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?(Fixnum)
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?{|day, selected| selected}
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{|day, selected| selected}
98
+ selected = @weekdays.select { |_day, day_selected| day_selected }
102
99
  # Ruby 1.8 returns an array for Hash#select and loses order
103
- selected.is_a?(Hash) ? selected.keys : selected.map(&:first).sort_by{|v| WEEKDAY_KEYS.index(v)}
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
- ALL_WEEKDAYS = WeekDays.new(%w(1 1 1 1 1 1 1))
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.0
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: 2017-11-29 00:00:00.000000000 Z
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.4.5.1
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.