expiry_calculator 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad6d87c333e5705c279b6e3748bb04ecf330d800639523d7d74e564b5c489bcf
4
+ data.tar.gz: 3185b744a8f58e03e2081ab989b830c1408103683c40a5d59e1ca1e7a9af95c6
5
+ SHA512:
6
+ metadata.gz: 92c3278652f83e8eb201b5d7c7f52db31fc17025c645ec803127bd08b27c4660a15d4a8582fc29ea26448b188b76b5db5cf768a92ec92b6c11ab5d3bbd509617
7
+ data.tar.gz: 472bc6e4be4827d1030475a005c7f6fb132f4435a1c5597e5f21d15b5f084533b715f32f03041021439698b0757c72e909af6bf4470a384e876033b6c66b31d4
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ expiry_calculator
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.1
data/.standard.yml ADDED
@@ -0,0 +1,7 @@
1
+ # For available configuration options, see: https://github.com/standardrb/standard.
2
+ ruby_version: 3.1
3
+
4
+ ignore:
5
+ - '*.gemspec':
6
+ - Gemspec/DeprecatedAttributeAssignment
7
+ - Layout/ExtraSpacing
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0] - 2025-03-17
2
+
3
+ - Initial release.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Expiry Calculator
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/expiry_calculator.svg)](https://rubygems.org/gems/expiry_calculator)
4
+ [![Build](https://github.com/abarrak/expiry_calculator/actions/workflows/ci.yml/badge.svg)](https://github.com/abarrak/expiry_calculator/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+
8
+ A ruby library that determines how much time left till certain date and time.
9
+
10
+ ## Installation
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ ```bash
15
+ bundle add expiry_calculator
16
+ ```
17
+
18
+ If bundler is not being used to manage dependencies, install the gem by executing:
19
+
20
+ ```bash
21
+ gem install expiry_calculator
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Add the library if gem auto loading is not available.
27
+
28
+ ```ruby
29
+ require "expiry_calculator"
30
+ ```
31
+
32
+ You can use the the extendable module method:
33
+
34
+ ```ruby
35
+ ExpiryCalculator.calculate(2025, 10, 10)
36
+ # => 201
37
+ ```
38
+
39
+ Or mix in to use the calcuate function directly:
40
+
41
+ ```ruby
42
+ include ExpiryCalculator
43
+
44
+ calculate Date.new(2025, 10, 10)
45
+ # => 201
46
+ ```
47
+
48
+ ```ruby
49
+ calculate "2025-01-10"
50
+ # => 0
51
+ ```
52
+
53
+ Active record models and be called with the date field needed to calculate:
54
+
55
+ ```ruby
56
+ user = User.first
57
+ calculate user, :birth_day
58
+ # => 15
59
+ ```
60
+
61
+
62
+ The supported objects:
63
+
64
+ - `Date`
65
+ - `DateTime`
66
+ - `string`: attempted to be parsed as datetime object.
67
+ - `ActiveRecord`: given an attribute of of the model to read as date object.
68
+
69
+ ## API Docs
70
+
71
+ The gem specs can [be found at RubyDocs.](https://www.rubydoc.info/gems/network-client/)
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome [on GitHub](https://github.com/abarrak/expiry_calculator).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,33 @@
1
+ module ExpiryCalculator
2
+ module Logic
3
+ ##
4
+ # A function to calculate the expiration from a given date.
5
+ #
6
+ # == Parameters:
7
+ #
8
+ # [*record*] +Date|DateTime|ApplicationRecord+: field of date and time to caluclate expiry for. Can be activerecord model containing a date field.
9
+ # [*record_attr*] +symbol|string+ The date attribute field in case of active record model is passed in first arguemtn. Default to nil.
10
+ #
11
+ # == Returns:
12
+ #
13
+ # The remaining days till the expiry, or zero if it already past.
14
+ #
15
+ #
16
+ def calculate record, record_attr = nil
17
+ expiry_date = case record
18
+ when Date
19
+ record
20
+ when DateTime
21
+ record
22
+ when String
23
+ DateTime.parse(record)
24
+ when ->(r) { defined?(ApplicationRecord) && r === ApplicationRecord }
25
+ record[record_attr.to_sym]
26
+ else
27
+ raise ArgumentError, "record type not supported."
28
+ end
29
+ days = (Date.today..expiry_date).count
30
+ days.zero? ? 0 : days - 1
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExpiryCalculator
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "expiry_calculator/logic"
4
+ require_relative "expiry_calculator/version"
5
+
6
+ module ExpiryCalculator
7
+ include ExpiryCalculator::Logic
8
+ end
@@ -0,0 +1,4 @@
1
+ module ExpiryCalculator
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: expiry_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdullah Barrak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_bot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.22.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.22.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-cobertura
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: standard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
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'
125
+ description: The library provides functionality to calculate the expiration from different
126
+ dates and time objects.
127
+ email:
128
+ - abdullah@abarrak.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".rspec"
134
+ - ".ruby-gemset"
135
+ - ".ruby-version"
136
+ - ".standard.yml"
137
+ - CHANGELOG.md
138
+ - README.md
139
+ - Rakefile
140
+ - lib/expiry_calculator.rb
141
+ - lib/expiry_calculator/logic.rb
142
+ - lib/expiry_calculator/version.rb
143
+ - sig/expiry_calculator.rbs
144
+ homepage: https://rubygems.org/gems/expiry_calculator
145
+ licenses:
146
+ - MIT
147
+ metadata:
148
+ homepage_uri: https://rubygems.org/gems/expiry_calculator
149
+ source_code_uri: https://github.com/abarrak/expiry_calculator
150
+ changelog_uri: https://github.com/abarrak/expiry_calculator/blob/main/CHANGELOG.md
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 3.1.0
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubygems_version: 3.5.9
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Determines how much time left till certain date.
170
+ test_files: []