wobbly 0.0.2 → 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 +16 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 357855b9037d8bc0799ed21d04905519a18a3148b66a4733e15f95e3ec6f1a84
4
- data.tar.gz: ab2861cb56726341222abad5cf9602add193e5fd3b9c7b5790fe4af83add5049
3
+ metadata.gz: 3293e7a30ccf12e04f7492e3e23ac7e5653574aeb05f4129cb257b3336891da9
4
+ data.tar.gz: 554b484de14088b74a91901cf5af4a4c23aab9e343523f97f6f8a620dfaf3204
5
5
  SHA512:
6
- metadata.gz: 902525bc6ae7276f63c1bc45c403b39a8c3acc33e2bea04e6dae3eb8db73cc8e404d4b5881506711ce4428209025cf1e709fc292fa6ded246e07a51c36588ba0
7
- data.tar.gz: e6475099c2c9c03d0a4c30e100a13febb69d464cb3493ce52d7ff6fbee164cf819f5cd937437212a3870c71e8704b950e5c26aee9a92db73f66e5f1586b1ed61
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,57 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wobbly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
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: 2017-11-27 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 5.7.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '5.7'
19
+ version: '5.25'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 5.7.0
30
24
  - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '5.7'
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'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 13.0.1
33
+ version: 13.2.1
43
34
  type: :development
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
- version: '13.0'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 13.0.1
53
- description: Wobbly is an easy to use token type date parser in Ruby that allows you
54
- 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.
55
44
  email: sean@isean.co.za
56
45
  executables:
57
46
  - wobbly
@@ -60,11 +49,11 @@ extra_rdoc_files: []
60
49
  files:
61
50
  - bin/wobbly
62
51
  - lib/wobbly.rb
63
- homepage: https://isean.co.za
52
+ homepage: https://github.com/sn/wobbly
64
53
  licenses:
65
- - GPL-3.0
54
+ - GPL-3.0-or-later
66
55
  metadata: {}
67
- post_install_message:
56
+ post_install_message:
68
57
  rdoc_options: []
69
58
  require_paths:
70
59
  - lib
@@ -72,15 +61,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
61
  requirements:
73
62
  - - ">="
74
63
  - !ruby/object:Gem::Version
75
- version: '0'
64
+ version: '2.7'
76
65
  required_rubygems_version: !ruby/object:Gem::Requirement
77
66
  requirements:
78
67
  - - ">="
79
68
  - !ruby/object:Gem::Version
80
69
  version: '0'
81
70
  requirements: []
82
- rubygems_version: 3.0.1
83
- signing_key:
71
+ rubygems_version: 3.5.22
72
+ signing_key:
84
73
  specification_version: 4
85
74
  summary: Wobbly is an easy to use token type date parser in Ruby
86
75
  test_files: []