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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2aff73c6ed5d9c3c36af73f5021e679dc4964f0105352450955a100448ad06f9
4
- data.tar.gz: d067a1b5f570a60ef306ba4f0b353382129c6836e66b0ebac58257f4355d9eec
3
+ metadata.gz: 06d12120e2aac71234bffdcbc59fa66bdf2cb07c623cdfc55d3b66206ed12b88
4
+ data.tar.gz: 2c24e3d132baa6cf0e8c3776feb43a6f065169e86c0ffaba5062bcf3d6b5ac88
5
5
  SHA512:
6
- metadata.gz: 8648f33b2048c16fbcb51433f8f13348afd3f0050715f0f7e90db51c62a2e9d2f8c98f81c821380dcd6eece94bd832bd9da4700bcc6906232e7b76354bc9b1e2
7
- data.tar.gz: de4b139d1ae262ba45fbb5678bcef41f9b3dc414feff7f9708a42951710611c4a241221f9bb74a440fc7a7474eac5d64cee8b0cf2ec2b33a255a28568240b1bc
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
- ## Usage
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
- ## Rails
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlusOrMinus
4
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/plus_or_minus.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "plus_or_minus/version"
4
- require "date"
3
+ require_relative 'plus_or_minus/version'
4
+ require 'date'
5
5
 
6
6
  module PlusOrMinus
7
- class Error < StandardError; end
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
- refine Time do
24
- import_methods InstanceMethods
25
- end
22
+ class Time
23
+ include PlusOrMinus::CoreExt
24
+ end
26
25
 
27
- refine DateTime do
28
- import_methods InstanceMethods
29
- end
26
+ class DateTime
27
+ include PlusOrMinus::CoreExt
28
+ end
30
29
 
31
- refine Numeric do
32
- import_methods InstanceMethods
33
- end
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.1.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-03 00:00:00.000000000 Z
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 refinement-based gem for numeric and date range calculations.
44
+ summary: A simple gem for numeric and date range calculations.
45
45
  test_files: []