theusual 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dacb5e7a014566aa0c349f8d1ebf456a7668657
4
- data.tar.gz: b7ef75744482e6bffd73885d698337619e130ac4
3
+ metadata.gz: 8629daa0932bdfb27fd4a6f0e6f7bce26f32b35d
4
+ data.tar.gz: 7873c20aa75d350cbea8cf3fd481dc14e86fcae6
5
5
  SHA512:
6
- metadata.gz: dc9842b4be2725073029d4fae4c424df5ea22cf7af53fa669c36cf8ab85fde7bdff882a5f05348b9b7385912e52a9cca759989be4715ee36922732eba7e82739
7
- data.tar.gz: 65cf8436c7fa60ed4b15f32267c5d5a15a8432f965a87e724cc5ed9bdd85a0f322e23c05384a8d2a1398bcfcca8eb79f925fd5ca061e13d6ac8812d975846a19
6
+ metadata.gz: 9b410fb90e5d42aed3cbfbfcda5574cec5383d944409c01ae2cf8dc42c3f3f4ef326ca6b1f0b43a7d0a30d9cda6c5709155eb1427edb625d1e6b093027d42e84
7
+ data.tar.gz: 73dc1e57c27bb0df0446d7b1d0688777676f4117074b94b3137fcf2562a5bb8604b718157278ba4c5330043c16ee8f678f4e1c401c7a2600ccc2d6790d5a5de5
@@ -10,6 +10,7 @@ module TheUsual
10
10
  'ipaddr',
11
11
  'mongoid',
12
12
  'net/ssh',
13
+ 'numeric',
13
14
  'string',
14
15
  'time',
15
16
  ]
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TheUsual
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -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.8
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-22 00:00:00.000000000 Z
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