wobbly 1.0.0 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wobbly.rb +21 -22
  3. metadata +15 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81bd676e78e90786dc883235b96a5c03b6b856e6f8357e3d4e50d0f11e1d550f
4
- data.tar.gz: f352d54eefcf0474141d1b8229985ef447d2bfbb1a6668f1602135960b6bcd90
3
+ metadata.gz: 3293e7a30ccf12e04f7492e3e23ac7e5653574aeb05f4129cb257b3336891da9
4
+ data.tar.gz: 554b484de14088b74a91901cf5af4a4c23aab9e343523f97f6f8a620dfaf3204
5
5
  SHA512:
6
- metadata.gz: 6423b9284403a81cd0a4808609288114fd915137f47cfbd19691e5f81e256e9290faa074fd83b71b688e7a048d483872829169115fadfdf152dbe62128189834
7
- data.tar.gz: 01daa094b28110c808a5a9e60151a2e3dce746479088318c5f6f0d601157b5abac351975c9cd1742a6736e858d69c3b2ab32c2abbe95de88b4549c4175334fd0
6
+ metadata.gz: 4b045ba4b69cd58e334fb5dbf9349f1e6931bbfe02b31a96c36eaf75ae1a5a35f8e2b5aa43e819b2e5a201d6e366f62f574a7cd42e3e2c1bd422a874de224f10
7
+ data.tar.gz: facb9eb2e4e834df372ba639659922b060e5f3b4cf4ea8d069a55ec6357b1a51c7b461583ddc1fae5c58f6ab03aa94a1a7652ca028531faa5b264d65eae99ff4
data/lib/wobbly.rb CHANGED
@@ -9,30 +9,29 @@ module Wobbly
9
9
  now = Time.now
10
10
 
11
11
  tokens(s).each do |t|
12
- token = t.gsub(/(\d+)/, '\1,').split(',')
13
-
14
- next if token.size != 2
15
-
16
- amt = token[0].to_i
17
- seg = token[1].to_s
12
+ # Use regex match to directly capture amount and segment
13
+ amt, seg = t.match(/(\d+)([smhDMWY])/).captures
14
+ amt = amt.to_i
18
15
 
19
16
  case seg
20
- when 's'
21
- now = now + amt
22
- when 'm'
23
- now = now + (amt*60)
24
- when 'h'
25
- now = now + (amt*60*60)
26
- when 'D'
27
- now = now + (amt*24*60*60)
28
- when 'W'
29
- now = now + (amt*7*24*60*60)
30
- when 'M'
31
- now = now + (amt*4*7*24*60*60)
32
- when 'Y'
33
- now = now + (amt*12*4*7*24*60*60)
34
- else
35
- raise "Invalid time segment provided #{seg}"
17
+ when 's'
18
+ now += amt
19
+ when 'm'
20
+ now += amt * 60
21
+ when 'h'
22
+ now += amt * 60 * 60
23
+ when 'D'
24
+ now += amt * 24 * 60 * 60
25
+ when 'W'
26
+ now += amt * 7 * 24 * 60 * 60
27
+ when 'M'
28
+ # Approximating 1 month as 30 days
29
+ now += amt * 30 * 24 * 60 * 60
30
+ when 'Y'
31
+ # Approximating 1 year as 365 days
32
+ now += amt * 365 * 24 * 60 * 60
33
+ else
34
+ raise ArgumentError, "Invalid time segment provided: #{seg}"
36
35
  end
37
36
  end
38
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wobbly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Nieuwoudt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-11 00:00:00.000000000 Z
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -16,36 +16,31 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.7'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.7.0
19
+ version: '5.25'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '5.7'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.7.0
26
+ version: '5.25'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '13.0'
33
+ version: 13.2.1
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '13.0'
47
- description: Wobbly is an easy to use token type date parser in Ruby that allows you
48
- easily parse short dates such as 1h2m
40
+ version: 13.2.1
41
+ description: Wobbly is a simple Ruby library that parses shorthand relative date and
42
+ time duration strings, making it easy to specify durations like '1h2m' (1 hour,
43
+ 2 minutes) or '5Y' (5 years) in a concise format.
49
44
  email: sean@isean.co.za
50
45
  executables:
51
46
  - wobbly
@@ -56,9 +51,9 @@ files:
56
51
  - lib/wobbly.rb
57
52
  homepage: https://github.com/sn/wobbly
58
53
  licenses:
59
- - GPL-3.0
54
+ - GPL-3.0-or-later
60
55
  metadata: {}
61
- post_install_message:
56
+ post_install_message:
62
57
  rdoc_options: []
63
58
  require_paths:
64
59
  - lib
@@ -66,15 +61,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
61
  requirements:
67
62
  - - ">="
68
63
  - !ruby/object:Gem::Version
69
- version: '0'
64
+ version: '2.7'
70
65
  required_rubygems_version: !ruby/object:Gem::Requirement
71
66
  requirements:
72
67
  - - ">="
73
68
  - !ruby/object:Gem::Version
74
69
  version: '0'
75
70
  requirements: []
76
- rubygems_version: 3.1.4
77
- signing_key:
71
+ rubygems_version: 3.5.22
72
+ signing_key:
78
73
  specification_version: 4
79
74
  summary: Wobbly is an easy to use token type date parser in Ruby
80
75
  test_files: []