nxt_support 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +4 -4
- data/README.md +12 -3
- data/lib/nxt_support/util.rb +1 -0
- data/lib/nxt_support/util/birth_date.rb +24 -0
- data/lib/nxt_support/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab20cd7b4c00a599718f2264dc905ce4308d9d4fe4b972b3a8e362892e0f349e
|
4
|
+
data.tar.gz: 38f2502b5a81e8cd8414cf42c98f84e8c21b2ae3e1cab66135f3b42fda72a0ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da8a6527d51c072f9356b9de520c41a29aad176d4890c5ab5644f73eb11313ff65e85501a5ab0ae71d7be855c983298518512cf254027e30973ed54d0150808
|
7
|
+
data.tar.gz: 0c5b59bf5d5a6a0270fcf82fa8e88bb3b1ebb393b3049d14b497849245790c21013c9c9248b46980d6b5415e001e4fcacc34e544d2584f3e71839974d1cf9e21
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_support (0.1.
|
4
|
+
nxt_support (0.1.8)
|
5
5
|
nxt_init
|
6
6
|
nxt_registry
|
7
7
|
rails
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
activesupport (>= 4.2.0)
|
75
75
|
i18n (1.8.5)
|
76
76
|
concurrent-ruby (~> 1.0)
|
77
|
-
loofah (2.
|
77
|
+
loofah (2.7.0)
|
78
78
|
crass (~> 1.0.2)
|
79
79
|
nokogiri (>= 1.5.9)
|
80
80
|
mail (2.7.1)
|
@@ -85,8 +85,8 @@ GEM
|
|
85
85
|
mimemagic (0.3.5)
|
86
86
|
mini_mime (1.0.2)
|
87
87
|
mini_portile2 (2.4.0)
|
88
|
-
minitest (5.14.
|
89
|
-
nio4r (2.5.
|
88
|
+
minitest (5.14.2)
|
89
|
+
nio4r (2.5.3)
|
90
90
|
nokogiri (1.10.10)
|
91
91
|
mini_portile2 (~> 2.4.0)
|
92
92
|
nxt_init (0.1.5)
|
data/README.md
CHANGED
@@ -250,9 +250,9 @@ TestClass.translate_hash(hash, tuple)
|
|
250
250
|
#### NxtSupport::Crystalizer
|
251
251
|
|
252
252
|
`NxtSupport::Crystalizer` crystallizes a shared value from an array of elements and screams in case the value is not
|
253
|
-
the same across the collection. This is useful in a scenario where you want to guarantee that certain objects share the same
|
254
|
-
attribute. Let's say you want to ensure that all users in your collection reference the same department, then the idea
|
255
|
-
is that you can crystallize the department from your collection.
|
253
|
+
the same across the collection. This is useful in a scenario where you want to guarantee that certain objects share the same
|
254
|
+
attribute. Let's say you want to ensure that all users in your collection reference the same department, then the idea
|
255
|
+
is that you can crystallize the department from your collection.
|
256
256
|
|
257
257
|
```ruby
|
258
258
|
NxtSupport::Crystalizer.new(collection: ['andy', 'andy']).call # => 'andy'
|
@@ -261,6 +261,15 @@ NxtSupport::Crystalizer.new(collection: ['andy', 'scotty']).call # NxtSupport::C
|
|
261
261
|
NxtSupport::Crystalizer.new(collection: insurances, attribute: :effective_at).call # => shared effective_at or error in case of different effective_ats
|
262
262
|
```
|
263
263
|
|
264
|
+
#### NxtSupport::BirthDate
|
265
|
+
|
266
|
+
`NxtSupport::BirthDate` takes a date and provides some convenience methods related to age.
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
NxtSupport::BirthDate.new(date: '1990-08-08').to_age # => 30
|
270
|
+
NxtSupport::BirthDate.new(date: '1990-08-08').to_age_in_months # => 361
|
271
|
+
```
|
272
|
+
|
264
273
|
## Development
|
265
274
|
|
266
275
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/nxt_support/util.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module NxtSupport
|
2
|
+
class BirthDate
|
3
|
+
include NxtInit
|
4
|
+
attr_init date: ->(date_or_string) { parse_date(date_or_string) }
|
5
|
+
|
6
|
+
def to_age(today = Date.current)
|
7
|
+
today.year - date.year - (today.month > date.month || (today.month == date.month && today.day >= date.day) ? 0 : 1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_age_in_months(today = Date.current)
|
11
|
+
(today.year * 12 + today.month) - (date.year * 12 + date.month)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_date
|
15
|
+
date
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse_date(date_or_string)
|
21
|
+
date_or_string.is_a?(Date) ? date_or_string : Date.parse(date_or_string)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/nxt_support/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nxt_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nils Sommer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/nxt_support/serializers.rb
|
160
160
|
- lib/nxt_support/serializers/has_time_attributes.rb
|
161
161
|
- lib/nxt_support/util.rb
|
162
|
+
- lib/nxt_support/util/birth_date.rb
|
162
163
|
- lib/nxt_support/util/crystalizer.rb
|
163
164
|
- lib/nxt_support/util/enum_hash.rb
|
164
165
|
- lib/nxt_support/util/hash_translator.rb
|
@@ -187,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
188
|
- !ruby/object:Gem::Version
|
188
189
|
version: '0'
|
189
190
|
requirements: []
|
190
|
-
rubygems_version: 3.0.
|
191
|
+
rubygems_version: 3.0.8
|
191
192
|
signing_key:
|
192
193
|
specification_version: 4
|
193
194
|
summary: Support through reusable Mixins and Helpers for Ruby on Rails Applications
|