theusual 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/theusual.rb +1 -0
- data/lib/theusual/numeric.rb +16 -0
- data/lib/theusual/version.rb +1 -1
- data/test/test_numeric.rb +37 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8629daa0932bdfb27fd4a6f0e6f7bce26f32b35d
|
4
|
+
data.tar.gz: 7873c20aa75d350cbea8cf3fd481dc14e86fcae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b410fb90e5d42aed3cbfbfcda5574cec5383d944409c01ae2cf8dc42c3f3f4ef326ca6b1f0b43a7d0a30d9cda6c5709155eb1427edb625d1e6b093027d42e84
|
7
|
+
data.tar.gz: 73dc1e57c27bb0df0446d7b1d0688777676f4117074b94b3137fcf2562a5bb8604b718157278ba4c5330043c16ee8f678f4e1c401c7a2600ccc2d6790d5a5de5
|
data/lib/theusual.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
Numeric.module_eval do |m|
|
2
|
+
m.const_set 'DELIMITER_REGEX', Regexp.new(/(\d)(?=(\d\d\d)+(?!\d))/)
|
3
|
+
|
4
|
+
def with_delimiter delimiter = ','
|
5
|
+
regex = Numeric.const_get 'DELIMITER_REGEX'
|
6
|
+
int = to_i.to_s.gsub regex do |digits|
|
7
|
+
"#{digits}#{delimiter}"
|
8
|
+
end
|
9
|
+
|
10
|
+
[
|
11
|
+
int,
|
12
|
+
to_s.split('.')[1]
|
13
|
+
].compact.join '.'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/theusual/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'theusual'
|
3
|
+
TheUsual::load :numeric
|
4
|
+
|
5
|
+
|
6
|
+
class NumericTest < Minitest::Test
|
7
|
+
|
8
|
+
def test_delimiter
|
9
|
+
# Integers
|
10
|
+
assert_equal(
|
11
|
+
'1,000',
|
12
|
+
1_000.with_delimiter
|
13
|
+
)
|
14
|
+
|
15
|
+
assert_equal(
|
16
|
+
'1,000,000',
|
17
|
+
1_000_000.with_delimiter
|
18
|
+
)
|
19
|
+
|
20
|
+
assert_equal(
|
21
|
+
'1_000',
|
22
|
+
1_000.with_delimiter('_')
|
23
|
+
)
|
24
|
+
|
25
|
+
# Floats
|
26
|
+
assert_equal(
|
27
|
+
'1,000.0',
|
28
|
+
1_000.0.with_delimiter
|
29
|
+
)
|
30
|
+
|
31
|
+
assert_equal(
|
32
|
+
'1,000.123',
|
33
|
+
1_000.123.with_delimiter
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theusual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/theusual/hash.rb
|
51
51
|
- lib/theusual/ipaddr.rb
|
52
52
|
- lib/theusual/mongoid.rb
|
53
|
+
- lib/theusual/numeric.rb
|
53
54
|
- lib/theusual/ssh.rb
|
54
55
|
- lib/theusual/string.rb
|
55
56
|
- lib/theusual/time.rb
|
@@ -58,6 +59,7 @@ files:
|
|
58
59
|
- test/test_failure.rb
|
59
60
|
- test/test_hash.rb
|
60
61
|
- test/test_ip_addr.rb
|
62
|
+
- test/test_numeric.rb
|
61
63
|
- test/test_string.rb
|
62
64
|
- test/test_time.rb
|
63
65
|
homepage: https://github.com/d1hotpep/theusualrb
|
@@ -89,5 +91,6 @@ test_files:
|
|
89
91
|
- test/test_failure.rb
|
90
92
|
- test/test_hash.rb
|
91
93
|
- test/test_ip_addr.rb
|
94
|
+
- test/test_numeric.rb
|
92
95
|
- test/test_string.rb
|
93
96
|
- test/test_time.rb
|