nxt_support 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9cd2e7ab48d6e58c2b05de88fecef08c69df0bf8bc5e9de3b1955b86d900187
4
- data.tar.gz: 155c904d6bdcc15d03ebae72b688f06bcf32cf497b3ac4728e447c23fa512727
3
+ metadata.gz: ab20cd7b4c00a599718f2264dc905ce4308d9d4fe4b972b3a8e362892e0f349e
4
+ data.tar.gz: 38f2502b5a81e8cd8414cf42c98f84e8c21b2ae3e1cab66135f3b42fda72a0ae
5
5
  SHA512:
6
- metadata.gz: 452a21d24a142cd56a027b5cfb835c37b4ecc16e2966dd27e3c41be364ecef75ff225bf23c06506e6b1a984aff42b27e09082a0be2360d27a92c8abfd036620e
7
- data.tar.gz: 9c6afc5fe2aa482f9cb3e76e158f681db66fd6c996d2f3dd831cb620489bbc96ec1a4540d892d1980c71bc59ba5039bfd671217efb7ed230f514855846c65d25
6
+ metadata.gz: 1da8a6527d51c072f9356b9de520c41a29aad176d4890c5ab5644f73eb11313ff65e85501a5ab0ae71d7be855c983298518512cf254027e30973ed54d0150808
7
+ data.tar.gz: 0c5b59bf5d5a6a0270fcf82fa8e88bb3b1ebb393b3049d14b497849245790c21013c9c9248b46980d6b5415e001e4fcacc34e544d2584f3e71839974d1cf9e21
@@ -1,3 +1,7 @@
1
+ # v0.1.8 2020-09-09
2
+
3
+ - Added `NxtSupport::BirthDate`
4
+
1
5
  # v0.1.7 2020-08-20
2
6
 
3
7
  - Added `NxtSupport::Crystalizer`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_support (0.1.7)
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.6.0)
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.1)
89
- nio4r (2.5.2)
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.
@@ -1,3 +1,4 @@
1
1
  require_relative 'util/enum_hash'
2
2
  require_relative 'util/hash_translator'
3
3
  require_relative 'util/crystalizer'
4
+ require_relative 'util/birth_date'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module NxtSupport
2
- VERSION = "0.1.7".freeze
2
+ VERSION = "0.1.8".freeze
3
3
  end
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.7
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-08-20 00:00:00.000000000 Z
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.3
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