king_konf 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/king_konf/decoder.rb +2 -0
- data/lib/king_konf/duration_decoder.rb +10 -8
- data/lib/king_konf/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cae3a1bc68bd4338074153f909aed61508c57843bd88201ffdb28c8151858a34
|
4
|
+
data.tar.gz: da575e0537725a6989483a557c17fe9a33d7d3e326b75b34db41ac04eab3dd0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1453e59b7cd31f5cade7b35f39f42cac78b44f99fa51e956daa034f81fbc84156c78e189151c8c1fb6fa84f1747f7a473286583fab5f4a7b3b336995f56944b7
|
7
|
+
data.tar.gz: b4e0eec7353d8c65bfe12d929bc3b38ac1905f5ccd0a07652d7beba12087b966b4bb297e68b948a141115137a5b6623aa716a2601c342665e48b18fdf327bebd
|
data/lib/king_konf/decoder.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module KingKonf
|
2
2
|
# Decodes specially formatted duration strings.
|
3
3
|
module DurationDecoder
|
4
|
+
UNITS = {
|
5
|
+
"ms" => 0.001,
|
6
|
+
"s" => 1,
|
7
|
+
"m" => 60,
|
8
|
+
"h" => 60 * 60,
|
9
|
+
"d" => 60 * 60 * 24,
|
10
|
+
"w" => 60 * 60 * 24 * 7,
|
11
|
+
}
|
12
|
+
|
4
13
|
# Either a number or a time unit.
|
5
|
-
PART = /(\d
|
14
|
+
PART = /(\d+|#{UNITS.keys.join('|')})/
|
6
15
|
|
7
16
|
# One or more parts, possibly separated by whitespace.
|
8
17
|
VALID_DURATION = /^(#{PART}\s*)+$/
|
9
18
|
|
10
|
-
UNITS = {
|
11
|
-
"s" => 1,
|
12
|
-
"m" => 60,
|
13
|
-
"h" => 60 * 60,
|
14
|
-
"d" => 60 * 60 * 24,
|
15
|
-
"w" => 60 * 60 * 24 * 7,
|
16
|
-
}
|
17
19
|
|
18
20
|
def self.decode(value)
|
19
21
|
if value !~ VALID_DURATION
|
data/lib/king_konf/version.rb
CHANGED