plus_or_minus 0.1.0 → 0.2.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/README.md +3 -16
- data/lib/plus_or_minus/version.rb +1 -1
- data/lib/plus_or_minus.rb +16 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06d12120e2aac71234bffdcbc59fa66bdf2cb07c623cdfc55d3b66206ed12b88
|
4
|
+
data.tar.gz: 2c24e3d132baa6cf0e8c3776feb43a6f065169e86c0ffaba5062bcf3d6b5ac88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46229cfa6d10c35cde7ca323e1a5c0d1405812ff564d6ec3518a8871e3b9c61aa1604958d26199a2df8745c1198afb9d98b9daa8b556e4fa7d0cad219af4451a
|
7
|
+
data.tar.gz: 5481aa01d05130504bea1f15f5d2f7e3a0ffaba55ae58f3548efa1fde6fbeb7a934fbb356cb4c5d6016e5d09903130e0a59273d7996aaca7c9d50f26394cfec5
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# PlusOrMinus
|
2
2
|
|
3
|
-
**PlusOrMinus** is a simple Ruby gem that extends `Time`, `DateTime`, and `Numeric` with convenient range methods for adding and subtracting values.
|
3
|
+
**PlusOrMinus** is a simple Ruby gem that extends `Time`, `DateTime`, `Date` and `Numeric` with convenient range methods for adding and subtracting values.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -14,13 +14,10 @@ And then execute `bundle install`
|
|
14
14
|
|
15
15
|
Or, install it manually with `gem install plus_or_minus`
|
16
16
|
|
17
|
-
##
|
18
|
-
|
19
|
-
To use PlusOrMinus, you need to enable the refinements within your scope:
|
17
|
+
## Usage
|
20
18
|
|
21
19
|
```ruby
|
22
20
|
require "plus_or_minus"
|
23
|
-
using PlusOrMinus
|
24
21
|
|
25
22
|
# Numeric
|
26
23
|
5.plus_or_minus(2) # => (3..7)
|
@@ -40,13 +37,11 @@ date.plus_upto(3) # => date..(date + 3.days)
|
|
40
37
|
date.minus_upto(3) # => (date - 3.days)..date
|
41
38
|
```
|
42
39
|
|
43
|
-
##
|
40
|
+
## Rails
|
44
41
|
|
45
42
|
If you're using Rails, PlusOrMinus works beautifully with ActiveRecord queries and Rails' time helpers:
|
46
43
|
|
47
44
|
```ruby
|
48
|
-
using PlusOrMinus
|
49
|
-
|
50
45
|
# Fetch users created within the last hour
|
51
46
|
User.where(created_at: Time.current.minus_upto(1.hour))
|
52
47
|
|
@@ -59,14 +54,6 @@ Order.where(due_date: Date.today.plus_upto(2.weeks))
|
|
59
54
|
# Fetch logs recorded within 5 minutes of a specific timestamp
|
60
55
|
Log.where(timestamp: some_time.plus_or_minus(5.minutes))
|
61
56
|
|
62
|
-
# With Paranoia or similar:
|
63
|
-
Model.where(deleted_at: parent.deleted_at.plus_or_minus(1.minute))
|
64
|
-
```
|
65
|
-
|
66
|
-
## Refinements
|
67
|
-
|
68
|
-
This gem uses refinements to extend Time, DateTime, and Numeric. To use it in a file, you must explicitly enable refinements with `using PlusOrMinus`.
|
69
|
-
|
70
57
|
## License
|
71
58
|
|
72
59
|
This gem is available as open-source under the MIT License.
|
data/lib/plus_or_minus.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
3
|
+
require_relative 'plus_or_minus/version'
|
4
|
+
require 'date'
|
5
5
|
|
6
6
|
module PlusOrMinus
|
7
|
-
|
8
|
-
|
9
|
-
module InstanceMethods
|
7
|
+
module CoreExt
|
10
8
|
def plus_or_minus(span)
|
11
9
|
(self - span)..(self + span)
|
12
10
|
end
|
@@ -19,16 +17,20 @@ module PlusOrMinus
|
|
19
17
|
(self - span)..self
|
20
18
|
end
|
21
19
|
end
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
class Time
|
23
|
+
include PlusOrMinus::CoreExt
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
class DateTime
|
27
|
+
include PlusOrMinus::CoreExt
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
class Date
|
31
|
+
include PlusOrMinus::CoreExt
|
32
|
+
end
|
33
|
+
|
34
|
+
class Numeric
|
35
|
+
include PlusOrMinus::CoreExt
|
34
36
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plus_or_minus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Dawson
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: PlusOrMinus refines Time, DateTime, and Numeric with convenient range
|
13
13
|
operations.
|
@@ -41,5 +41,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
requirements: []
|
42
42
|
rubygems_version: 3.6.2
|
43
43
|
specification_version: 4
|
44
|
-
summary: A simple
|
44
|
+
summary: A simple gem for numeric and date range calculations.
|
45
45
|
test_files: []
|