dateslash 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 +7 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/lib/dateslash/version.rb +5 -0
- data/lib/dateslash.rb +26 -0
- data/sig/dateslash.rbs +33 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7d6ced45484eb8ba6121b45c16f58e717ac99e59a8ad72143945247a92a475ac
|
|
4
|
+
data.tar.gz: 6ea460b24e004d82dfbaf96805e54019a28893a80f29ebe13ca2b87f3b0e86c2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fc1767583fa5c30dbc28f6eb2589e864e8fe51035b11e4714eacdee83cfb90c6ba03eeddc5b90e5b49c20640a5fae52e036221734bac26d27571425e43c2ec09
|
|
7
|
+
data.tar.gz: e41c0e4f8b6d104c47c99ebaa9a21c1bde75fdba20e8b536be6afa60b138354a8b9a32bf7eb124370e30648bdb43a59c65939c4cff5c164eb5a3660b2b6d968d
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"dateslash" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at [Issue](https://github.com/t3tra-dev/dateslash/issues).
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 t3tra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# DateSlash
|
|
2
|
+
|
|
3
|
+
DateSlash adds a Ruby refinement that makes year/month/day expressions readable with `/`.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
using DateSlash
|
|
7
|
+
|
|
8
|
+
2026 / 8
|
|
9
|
+
# => 253
|
|
10
|
+
|
|
11
|
+
2026 / 8 / 18
|
|
12
|
+
# => #<Date: 2026-08-18 ...>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The first `/` returns an intermediate object that still behaves like the integer quotient of `year / month`. The second `/` converts that intermediate value into a `Date` only when the expression has exactly three terms and they form a valid calendar date.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add the gem to your application:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle add dateslash
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install it directly:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
gem install dateslash
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
Require the gem and enable the refinement in the scope where you want to use it.
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
require "dateslash"
|
|
37
|
+
|
|
38
|
+
using DateSlash
|
|
39
|
+
|
|
40
|
+
date = 2026 / 8 / 18
|
|
41
|
+
date.class
|
|
42
|
+
# => Date
|
|
43
|
+
|
|
44
|
+
prefix = 2026 / 8
|
|
45
|
+
prefix.to_i
|
|
46
|
+
# => 253
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The refinement only applies when the left-hand side is a four-digit year, the month is from 1 to 12, and the complete date is valid. Invalid dates and expressions with four or more terms keep Ruby's normal division behavior.
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
using DateSlash
|
|
53
|
+
|
|
54
|
+
10 / 2
|
|
55
|
+
# => 5
|
|
56
|
+
|
|
57
|
+
2026 / 13
|
|
58
|
+
# => 155
|
|
59
|
+
|
|
60
|
+
2026 / 2 / 29
|
|
61
|
+
# => 34
|
|
62
|
+
|
|
63
|
+
2026 / 8 / 18 / 2
|
|
64
|
+
# => 7
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
After checking out the repo, run:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
bin/setup
|
|
73
|
+
bundle exec rake test
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You can also use `bin/console` to try the refinement interactively.
|
|
77
|
+
|
|
78
|
+
To install the gem locally:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
bundle exec rake install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
To release a new version, update [lib/dateslash/version.rb](lib/dateslash/version.rb) and run:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bundle exec rake release
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
The gem is available as open source under the terms of the MIT License.
|
|
93
|
+
|
|
94
|
+
## Code of Conduct
|
|
95
|
+
|
|
96
|
+
Everyone interacting in this project is expected to follow the code of conduct in [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/dateslash.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
require_relative "dateslash/date_prefix"
|
|
5
|
+
require_relative "dateslash/version"
|
|
6
|
+
|
|
7
|
+
module DateSlash
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
YEAR_RANGE = (1000..9999)
|
|
11
|
+
MONTH_RANGE = (1..12)
|
|
12
|
+
DAY_RANGE = (1..31)
|
|
13
|
+
|
|
14
|
+
refine Integer do
|
|
15
|
+
def /(other)
|
|
16
|
+
if DateSlash::YEAR_RANGE.cover?(self) &&
|
|
17
|
+
other.is_a?(Integer) &&
|
|
18
|
+
DateSlash::MONTH_RANGE.cover?(other)
|
|
19
|
+
DateSlash::DatePrefix.new(self, other, div(other))
|
|
20
|
+
else
|
|
21
|
+
quotient = super
|
|
22
|
+
DateSlash::DivisionResult.wrap(quotient)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/sig/dateslash.rbs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module DateSlash
|
|
2
|
+
VERSION: String
|
|
3
|
+
YEAR_RANGE: Range[Integer]
|
|
4
|
+
MONTH_RANGE: Range[Integer]
|
|
5
|
+
DAY_RANGE: Range[Integer]
|
|
6
|
+
|
|
7
|
+
class DivisionValue < Numeric
|
|
8
|
+
def initialize: (Numeric quotient) -> void
|
|
9
|
+
def ==: (untyped other) -> bool
|
|
10
|
+
def <=>: (untyped other) -> Integer?
|
|
11
|
+
def coerce: (Numeric other) -> [Numeric, Numeric]
|
|
12
|
+
def inspect: () -> String
|
|
13
|
+
def to_s: () -> String
|
|
14
|
+
def to_i: () -> Integer
|
|
15
|
+
def to_int: () -> Integer
|
|
16
|
+
def to_f: () -> Float
|
|
17
|
+
def integer?: () -> bool
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class DivisionResult < DivisionValue
|
|
21
|
+
def self.wrap: (Numeric quotient) -> Numeric
|
|
22
|
+
def /: (untyped other) -> Numeric
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class DatePrefix
|
|
26
|
+
def initialize: (Integer year, Integer month, Integer quotient) -> void
|
|
27
|
+
def /: (untyped day) -> (Date | Numeric)
|
|
28
|
+
def inspect: () -> String
|
|
29
|
+
def to_s: () -> String
|
|
30
|
+
def to_i: () -> Integer
|
|
31
|
+
def to_int: () -> Integer
|
|
32
|
+
end
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dateslash
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- t3tra
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: DateSlash lets you write expressions like 2026 / 8 / 18 and get a Date
|
|
13
|
+
object while preserving normal integer division elsewhere.
|
|
14
|
+
email:
|
|
15
|
+
- t3tra-dev@users.noreply.github.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- CODE_OF_CONDUCT.md
|
|
22
|
+
- LICENSE.txt
|
|
23
|
+
- README.md
|
|
24
|
+
- Rakefile
|
|
25
|
+
- lib/dateslash.rb
|
|
26
|
+
- lib/dateslash/version.rb
|
|
27
|
+
- sig/dateslash.rbs
|
|
28
|
+
homepage: https://github.com/t3tra-dev/dateslash
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata:
|
|
32
|
+
homepage_uri: https://github.com/t3tra-dev/dateslash
|
|
33
|
+
source_code_uri: https://github.com/t3tra-dev/dateslash
|
|
34
|
+
changelog_uri: https://github.com/t3tra-dev/dateslash/blob/main/CHANGELOG.md
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 3.2.0
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubygems_version: 3.6.9
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Readable year/month/day expressions via a Ruby refinement
|
|
52
|
+
test_files: []
|