string-utility 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/utils.rb +16 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f92b1066574eae3c7e4ce1e67373585e0281d66
|
4
|
+
data.tar.gz: d8ece5bd0236fd66f7145eacdc7454cba36a458c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d898cd1faf347f593f501d4cf0ce6e3a366f8e777c7bf790d7c5c3e3306dbbf0873fa074cc256adc52b2dd03bb4c1a0553d9a26a968106cbe0c5175fb831b06
|
7
|
+
data.tar.gz: 7e77a383f86c55df46e4a6e0110860c8cd92faa8d32fec02da30e0babfd85b7f08c3331378ad6d1d4825769735a75c471d431db01ea6d3b44ca0e6efe4e8a821
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
|
-
## Version
|
2
|
+
## Version 2
|
3
|
+
### Version 2.0.0
|
4
|
+
* There is no longer an initialize method.
|
5
|
+
* separate is now a monkeypatch using the refine keyword.
|
6
|
+
|
3
7
|
### Version 1.0.1
|
4
8
|
* No longer need to create an instance of StringUtility. Not really sure why I made that the case in the first place.
|
5
9
|
### Version 1.0.0
|
data/lib/utils.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
|
1
|
+
module StringUtility
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
refine String do
|
4
|
+
# Separates the string by another string. Useful for converting integers into human-readable numbers.
|
5
|
+
# @param count [Int] The number of integers to separate by. Defaults to 3.
|
6
|
+
# @param separator [String] The string to use as a separator. Can only be 1 character long. Will use the first character if it is greater than 1 character long. Defaults to a comma.
|
7
|
+
# @return [String] Formatted version of the provided string.
|
8
|
+
def separate(count = 3, separator = ',')
|
9
|
+
if separator.length > 1
|
10
|
+
separator = separator[0]
|
11
|
+
end
|
12
|
+
string = self
|
13
|
+
string = string.reverse
|
14
|
+
array = string.scan(/.{1,#{count}}/)
|
15
|
+
string = array.join(separator)
|
16
|
+
string = string.reverse
|
17
|
+
return string
|
14
18
|
end
|
15
|
-
string = string.reverse!
|
16
|
-
array = string.scan(/.{1,#{count}}/)
|
17
|
-
string = array.join(separator)
|
18
|
-
string = string.reverse!
|
19
|
-
return string
|
20
19
|
end
|
21
20
|
end
|