darthjee-core_ext 1.3.1 → 1.4.0
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/DATE_README.md +19 -0
- data/README.md +4 -0
- data/SYMBOL_README.md +46 -0
- data/lib/darthjee/core_ext.rb +7 -5
- data/lib/{array.rb → darthjee/core_ext/array.rb} +1 -1
- data/lib/{array → darthjee/core_ext/array}/hash_builder.rb +0 -0
- data/lib/darthjee/core_ext/date.rb +5 -0
- data/lib/{enumerable.rb → darthjee/core_ext/enumerable.rb} +0 -0
- data/lib/{hash.rb → darthjee/core_ext/hash.rb} +3 -3
- data/lib/{hash → darthjee/core_ext/hash}/deep_hash_constructor.rb +0 -0
- data/lib/{hash → darthjee/core_ext/hash}/key_changer.rb +0 -0
- data/lib/{hash → darthjee/core_ext/hash}/value_changer.rb +0 -0
- data/lib/{numeric.rb → darthjee/core_ext/numeric.rb} +0 -0
- data/lib/{symbol.rb → darthjee/core_ext/symbol.rb} +0 -0
- data/lib/darthjee/core_ext/time.rb +3 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/spec/lib/date_spec.rb +12 -0
- data/spec/lib/time_spec.rb +12 -0
- data/spec/support/shared_examples/date.rb +73 -0
- metadata +21 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2345bf7cdf843714d515bb2bee9466683401837
|
4
|
+
data.tar.gz: 5e05050eabe46f189e9a1bd7dea334de6589fdbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884c6906d6ecf48a9f2daeafe4802506e1add3cc46f49335dc6adda8d408bcd0b9cfaa3ce1eceeeb16f9d82ce31b435cb82fdff2b37e194af08f77bc09272455
|
7
|
+
data.tar.gz: 4c61c2a039d1af1309367b6058af1ce141abd8d37e10923f19fa15d5ba5bd161fb7fc6c789a883ef8b46c2f88e24d13f75b31846ff125cfb4945b6b1a612189d
|
data/DATE_README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## Date
|
2
|
+
|
3
|
+
### #days_between
|
4
|
+
|
5
|
+
Returns the number of days between 2 dates
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
d1 = Date.new(2106, 10, 11)
|
9
|
+
d2 = d1 + 1.year
|
10
|
+
d3 = d1 - 1,year
|
11
|
+
```
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
d1.days_between(d2) == 365
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
d1.days_between(d3) = 366
|
19
|
+
```
|
data/README.md
CHANGED
@@ -26,9 +26,13 @@ bundle install darthjee-core_ext
|
|
26
26
|
|
27
27
|
# methods added
|
28
28
|
|
29
|
+
## Symbol
|
30
|
+
[SYMBOL_README.md](SYMBOL_README.md)
|
29
31
|
## Array
|
30
32
|
[ARRAY_README.md](ARRAY_README.md)
|
31
33
|
## Hash
|
32
34
|
[HASH_README.md](HASH_README.md)
|
33
35
|
## Enumerable
|
34
36
|
[ENUMERABLE_README.md](ENUMERABLE_README.md)
|
37
|
+
## Date
|
38
|
+
[DATE_README.md](DATE_README.md)
|
data/SYMBOL_README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
## Symbol
|
2
|
+
|
3
|
+
### #camelize
|
4
|
+
Camelize the symbol 'just like String#camelize'
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
:underscore_sym.camelize(:upper)
|
8
|
+
```
|
9
|
+
|
10
|
+
Returns
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
:UnderscoreSym
|
14
|
+
```
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
:underscore_sym.camelize(:lower)
|
18
|
+
```
|
19
|
+
Returns
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
:underscoreSym
|
23
|
+
```
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
:underscore_sym.camelize
|
27
|
+
```
|
28
|
+
|
29
|
+
Return
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
:UnderscoreSym
|
33
|
+
```
|
34
|
+
|
35
|
+
### #underscore
|
36
|
+
underscore the symbol 'just like String#underscore'
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
:symBol.underscore
|
40
|
+
```
|
41
|
+
|
42
|
+
Returns
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
:sym_bol
|
46
|
+
```
|
data/lib/darthjee/core_ext.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require 'enumerable'
|
2
1
|
require 'active_support/all'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
2
|
+
require 'darthjee/core_ext/enumerable'
|
3
|
+
require 'darthjee/core_ext/hash'
|
4
|
+
require 'darthjee/core_ext/symbol'
|
5
|
+
require 'darthjee/core_ext/array'
|
6
|
+
require 'darthjee/core_ext/numeric'
|
7
|
+
require 'darthjee/core_ext/date'
|
8
|
+
require 'darthjee/core_ext/time'
|
7
9
|
|
8
10
|
module Darthjee
|
9
11
|
module CoreExt
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'hash/value_changer'
|
2
|
-
require 'hash/deep_hash_constructor'
|
3
|
-
require 'hash/key_changer'
|
1
|
+
require 'darthjee/core_ext/hash/value_changer'
|
2
|
+
require 'darthjee/core_ext/hash/deep_hash_constructor'
|
3
|
+
require 'darthjee/core_ext/hash/key_changer'
|
4
4
|
|
5
5
|
class Hash
|
6
6
|
def chain_fetch(*keys)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Date do
|
4
|
+
let(:year) { 2018 }
|
5
|
+
let(:month) { 10 }
|
6
|
+
let(:day) { 4 }
|
7
|
+
let(:subject) { Date.new(year, month, day) }
|
8
|
+
|
9
|
+
describe '#days_between' do
|
10
|
+
it_behaves_like 'an object that knows how to calculate days between'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Time do
|
4
|
+
let(:year) { 2018 }
|
5
|
+
let(:month) { 10 }
|
6
|
+
let(:day) { 4 }
|
7
|
+
let(:subject) { Time.new(year, month, day, 10, 0, 0) }
|
8
|
+
|
9
|
+
describe '#days_between' do
|
10
|
+
it_behaves_like 'an object that knows how to calculate days between'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
shared_examples 'an object that knows how to calculate days between' do
|
2
|
+
let(:other_date) { subject.to_date + difference }
|
3
|
+
let(:difference) { 1.year }
|
4
|
+
|
5
|
+
context 'when other object is a date' do
|
6
|
+
context 'when other date is one year ahead' do
|
7
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when other date is one year behind' do
|
11
|
+
let(:difference) { - 1.year }
|
12
|
+
|
13
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when initial date is on a leap year' do
|
17
|
+
let(:year) { 2016 }
|
18
|
+
|
19
|
+
context 'when other date is one year ahead' do
|
20
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when other date is one year behind' do
|
24
|
+
let(:difference) { - 1.year }
|
25
|
+
|
26
|
+
it { expect(subject.days_between(other_date)).to eq(366) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when initial date is before a leap year' do
|
31
|
+
let(:year) { 2015 }
|
32
|
+
|
33
|
+
context 'when other date is one year ahead' do
|
34
|
+
it { expect(subject.days_between(other_date)).to eq(366) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when other date is one year behind' do
|
38
|
+
let(:difference) { - 1.year }
|
39
|
+
|
40
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when other date is a time' do
|
46
|
+
let(:other_date) { subject.to_date.to_time + difference }
|
47
|
+
|
48
|
+
context 'when other date is one year and 10 hours ahead' do
|
49
|
+
let(:difference) { 1.year + 10.hours }
|
50
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when other date is one year and 25 hours ahead' do
|
54
|
+
let(:difference) { 1.year + 25.hours }
|
55
|
+
it { expect(subject.days_between(other_date)).to eq(366) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when other date is one year and 23 hours ahead' do
|
59
|
+
let(:difference) { 1.year + 23.hours }
|
60
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when other date is one year and 10 hours behind' do
|
64
|
+
let(:difference) { - 1.year - 10.hours }
|
65
|
+
it { expect(subject.days_between(other_date)).to eq(366) }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when other date is almost one year behind (missing 10 hours)' do
|
69
|
+
let(:difference) { -1.year + 10.hours }
|
70
|
+
it { expect(subject.days_between(other_date)).to eq(365) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darthjee-core_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,33 +132,39 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
134
|
- ARRAY_README.md
|
135
|
+
- DATE_README.md
|
135
136
|
- ENUMERABLE_README.md
|
136
137
|
- Gemfile
|
137
138
|
- HASH_README.md
|
138
139
|
- LICENSE
|
139
140
|
- README.md
|
140
141
|
- Rakefile
|
142
|
+
- SYMBOL_README.md
|
141
143
|
- circle.yml
|
142
144
|
- core_ext.gemspec
|
143
|
-
- lib/array.rb
|
144
|
-
- lib/array/hash_builder.rb
|
145
145
|
- lib/darthjee.rb
|
146
146
|
- lib/darthjee/core_ext.rb
|
147
|
+
- lib/darthjee/core_ext/array.rb
|
148
|
+
- lib/darthjee/core_ext/array/hash_builder.rb
|
149
|
+
- lib/darthjee/core_ext/date.rb
|
150
|
+
- lib/darthjee/core_ext/enumerable.rb
|
151
|
+
- lib/darthjee/core_ext/hash.rb
|
152
|
+
- lib/darthjee/core_ext/hash/deep_hash_constructor.rb
|
153
|
+
- lib/darthjee/core_ext/hash/key_changer.rb
|
154
|
+
- lib/darthjee/core_ext/hash/value_changer.rb
|
155
|
+
- lib/darthjee/core_ext/numeric.rb
|
156
|
+
- lib/darthjee/core_ext/symbol.rb
|
157
|
+
- lib/darthjee/core_ext/time.rb
|
147
158
|
- lib/darthjee/core_ext/version.rb
|
148
|
-
- lib/enumerable.rb
|
149
|
-
- lib/hash.rb
|
150
|
-
- lib/hash/deep_hash_constructor.rb
|
151
|
-
- lib/hash/key_changer.rb
|
152
|
-
- lib/hash/value_changer.rb
|
153
|
-
- lib/numeric.rb
|
154
|
-
- lib/symbol.rb
|
155
159
|
- spec/lib/array_spec.rb
|
160
|
+
- spec/lib/date_spec.rb
|
156
161
|
- spec/lib/enumerable_spec.rb
|
157
162
|
- spec/lib/hash/deep_hash_constructor_spec.rb
|
158
163
|
- spec/lib/hash/key_changer_spec.rb
|
159
164
|
- spec/lib/hash_spec.rb
|
160
165
|
- spec/lib/numeric_spec.rb
|
161
166
|
- spec/lib/symbol_spec.rb
|
167
|
+
- spec/lib/time_spec.rb
|
162
168
|
- spec/spec_helper.rb
|
163
169
|
- spec/support/models/hash/value_changer/dummy.rb
|
164
170
|
- spec/support/models/hash/value_changer/dummy_iteractor.rb
|
@@ -166,6 +172,7 @@ files:
|
|
166
172
|
- spec/support/shared_examples/chain_fetch.rb
|
167
173
|
- spec/support/shared_examples/chain_hash_keys_changer.rb
|
168
174
|
- spec/support/shared_examples/clean.rb
|
175
|
+
- spec/support/shared_examples/date.rb
|
169
176
|
- spec/support/shared_examples/expected.rb
|
170
177
|
- spec/support/shared_examples/hash_keys_changer.rb
|
171
178
|
- spec/support/shared_examples/keys_appender.rb
|
@@ -199,12 +206,14 @@ specification_version: 4
|
|
199
206
|
summary: Core Extensions
|
200
207
|
test_files:
|
201
208
|
- spec/lib/array_spec.rb
|
209
|
+
- spec/lib/date_spec.rb
|
202
210
|
- spec/lib/enumerable_spec.rb
|
203
211
|
- spec/lib/hash/deep_hash_constructor_spec.rb
|
204
212
|
- spec/lib/hash/key_changer_spec.rb
|
205
213
|
- spec/lib/hash_spec.rb
|
206
214
|
- spec/lib/numeric_spec.rb
|
207
215
|
- spec/lib/symbol_spec.rb
|
216
|
+
- spec/lib/time_spec.rb
|
208
217
|
- spec/spec_helper.rb
|
209
218
|
- spec/support/models/hash/value_changer/dummy.rb
|
210
219
|
- spec/support/models/hash/value_changer/dummy_iteractor.rb
|
@@ -212,6 +221,7 @@ test_files:
|
|
212
221
|
- spec/support/shared_examples/chain_fetch.rb
|
213
222
|
- spec/support/shared_examples/chain_hash_keys_changer.rb
|
214
223
|
- spec/support/shared_examples/clean.rb
|
224
|
+
- spec/support/shared_examples/date.rb
|
215
225
|
- spec/support/shared_examples/expected.rb
|
216
226
|
- spec/support/shared_examples/hash_keys_changer.rb
|
217
227
|
- spec/support/shared_examples/keys_appender.rb
|