string-utility 2.7.3 → 3.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 +12 -0
- data/lib/utils.rb +36 -26
- metadata +4 -9
- data/ext/Cargo.toml +0 -16
- data/ext/Makefile +0 -7
- data/ext/extconf.rb +0 -1
- data/ext/src/lib.rs +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e1b97ed7145c00bb717a2e8fa57683cfac3297
|
4
|
+
data.tar.gz: 19f34fccbd7246f8872eaefdf952f825e62ebb73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0fbe197ee5d28cb514ff235d07c424c1aa39ed8a487b592de9ac0442093b1666c86b0753ea1e68b05958eacca4d0ab1738face77d7471969e77a0b4e1cbe125
|
7
|
+
data.tar.gz: cb83fbb6f3c57aca226cfa4223553631793fd7184810cfd6ec5c5e974e891fd04fb08f447b42d3ee448223147c6f60202f8830ab92fba301a0ac5cdeee5c3589
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
# Changelog
|
2
|
+
## Version 3
|
3
|
+
### Version 3.0.0
|
4
|
+
* Improved test coverage and accuracy significantly by (a) having more tests; and (b) having tests cover return values as well as self-modification non-return values (i.e., checking what happens *after* a bang method is called).
|
5
|
+
* `spacify` and `underscorify` are no longer Rust native extensions. The Ruby methods were not slow enough to warrant native extensions, and this was complicated when using external build services like Heroku.
|
6
|
+
* `to_i_separated` no longer modifies the source string (it is non-destructive).
|
7
|
+
* `underscorify` is no longer destructive.
|
8
|
+
* New method `underscorify!`, destructive version of `underscorify`.
|
9
|
+
* `spacify` is no longer destructive.
|
10
|
+
* New method `spacify!`, destructive version of `spacify`.
|
11
|
+
* Remove `safely_gsub!`, as it undermines the actual usage of `gsub!` (you probably aren't going to be doing `str = str.gsub!('a', 'b')`, and if you are, you are using it wrongly.)
|
12
|
+
* New method `separate!`, destructive version of `separate`.
|
13
|
+
|
2
14
|
## Version 2
|
3
15
|
### Version 2.7.3
|
4
16
|
* Optimize underscorify and spacify with native extensions written in Rust, utilizing the ruru crate. These methods are now 2-5x faster. I did attempt to write a Rust extension for random_line, the slowest function in this library, but the performance increase was insignificant.
|
data/lib/utils.rb
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
require 'fiddle'
|
2
|
-
|
3
|
-
LIBRARY = Fiddle.dlopen("#{File.dirname(__FILE__)}/../ext/target/release/libstringutility.dylib")
|
4
|
-
|
5
1
|
module StringUtility
|
6
|
-
Fiddle::Function.new(LIBRARY['initialize_me'], [], Fiddle::TYPE_VOIDP).call
|
7
2
|
refine String do
|
8
3
|
# Separates the string by another string. Useful for converting integers
|
9
4
|
# into human-readable numbers.
|
@@ -16,20 +11,46 @@ module StringUtility
|
|
16
11
|
chars.reverse!.each_slice(count).map(&:join).join(separator[0]).reverse!
|
17
12
|
end
|
18
13
|
|
19
|
-
#
|
20
|
-
#
|
14
|
+
# In-place version of #separate. This is about two times slower than the non-destructive variant. This is because
|
15
|
+
# the destructive version (this one) uses regular expressions to insert the string.
|
16
|
+
# see #separate
|
17
|
+
def separate!(count = 3, separator = ',')
|
18
|
+
reverse!
|
19
|
+
gsub!(/(.{#{count}})/, "\\1#{separator[0]}")
|
20
|
+
# Because of that regular expression, sometimes a separator character will be inserted at the end.
|
21
|
+
# For example, '1000'.separate!(2) would result in ,10,00.
|
22
|
+
# This is not ideal, but it works.
|
23
|
+
chomp!(separator[0])
|
24
|
+
reverse!
|
25
|
+
end
|
26
|
+
|
27
|
+
# Converts a separated string into an integer. This is basically the reverse of #separate. Does not modify the
|
28
|
+
# source string.
|
21
29
|
# @return [Integer] The integer version of the separated string.
|
22
30
|
def to_i_separated
|
23
|
-
|
31
|
+
gsub(/\D/, '').to_i
|
24
32
|
end
|
25
33
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
# Replaces all whitespace with underscores. Does not modify the source string.
|
35
|
+
# @return [String] A new string with replaced whitespace.
|
36
|
+
def underscorify
|
37
|
+
gsub(/\s/, '_')
|
38
|
+
end
|
39
|
+
|
40
|
+
# Replaces all whitespace with underscores. Modifies the source string in-place.
|
41
|
+
def underscorify!
|
42
|
+
gsub!(/\s/, '_')
|
43
|
+
end
|
44
|
+
|
45
|
+
# Replaces all underscores with whitespace. Does not modify the source string.
|
46
|
+
# @return [String] A new string with replaced underscores.
|
47
|
+
def spacify
|
48
|
+
gsub('_', ' ')
|
49
|
+
end
|
50
|
+
|
51
|
+
# Replaces all underscores with whitespace. Modifies the source string in-place.
|
52
|
+
def spacify!
|
53
|
+
gsub!('_', ' ')
|
33
54
|
end
|
34
55
|
end
|
35
56
|
|
@@ -70,14 +91,3 @@ module StringUtility
|
|
70
91
|
str
|
71
92
|
end
|
72
93
|
end
|
73
|
-
|
74
|
-
# A module that contains stub methods for the Rust native extension methods.
|
75
|
-
module StringUtilityNativeExtensionDocumentationStubs
|
76
|
-
# Replaces all whitespace with underscores.
|
77
|
-
# @return [String] The string with replaced whitespace.
|
78
|
-
def underscorify; end
|
79
|
-
|
80
|
-
# Replaces all underscores with whitespace.
|
81
|
-
# @return [String] The string with replaced underscores.
|
82
|
-
def spacify; end
|
83
|
-
end
|
metadata
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string-utility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Some simple but handy methods to interact with string objects.\n"
|
14
14
|
email: elifosterwy@gmail.com
|
15
15
|
executables: []
|
16
|
-
extensions:
|
17
|
-
- ext/extconf.rb
|
16
|
+
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
20
19
|
- CHANGELOG.md
|
21
|
-
- ext/Cargo.toml
|
22
|
-
- ext/Makefile
|
23
|
-
- ext/extconf.rb
|
24
|
-
- ext/src/lib.rs
|
25
20
|
- lib/string-utility.rb
|
26
21
|
- lib/utils.rb
|
27
22
|
homepage: https://github.com/elifoster/string-utility-ruby
|
@@ -45,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
40
|
version: '0'
|
46
41
|
requirements: []
|
47
42
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.6.8
|
49
44
|
signing_key:
|
50
45
|
specification_version: 4
|
51
46
|
summary: Provides some basic utilities for interacting with Strings
|
data/ext/Cargo.toml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
[package]
|
2
|
-
name = "string-utility-rb-native"
|
3
|
-
version = "1.0.0"
|
4
|
-
authors = ["Eli Clemente Gordillo Foster <elifosterwy@gmail.com>"]
|
5
|
-
homepage = "https://rubygems.org/gems/string-utility"
|
6
|
-
repository = "https://github.com/elifoster/String-Utility-Ruby"
|
7
|
-
readme = "README.md"
|
8
|
-
license = "MIT"
|
9
|
-
description = "The Rust native extension for the StringUtility Ruby gem."
|
10
|
-
|
11
|
-
[lib]
|
12
|
-
name = "stringutility"
|
13
|
-
crate-type = ["dylib"]
|
14
|
-
|
15
|
-
[dependencies]
|
16
|
-
ruru = "0.7"
|
data/ext/Makefile
DELETED
data/ext/extconf.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
fail 'You have to install Rust with Cargo (https://www.rust-lang.org/)' if !system('cargo --version') || !system('rustc --version')
|
data/ext/src/lib.rs
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#[macro_use]
|
2
|
-
extern crate ruru;
|
3
|
-
|
4
|
-
use ruru::{AnyObject, Class, RString, VM};
|
5
|
-
use ruru::types::{Argc, Value};
|
6
|
-
use ruru::traits::Object;
|
7
|
-
|
8
|
-
class!(StringUtility);
|
9
|
-
|
10
|
-
methods!(
|
11
|
-
RString,
|
12
|
-
itself,
|
13
|
-
|
14
|
-
fn underscorify() -> RString {
|
15
|
-
RString::new(&str::replace(&itself.to_string(), " ", "_"))
|
16
|
-
}
|
17
|
-
|
18
|
-
fn spacify() -> RString {
|
19
|
-
RString::new(&str::replace(&itself.to_string(), "_", " "))
|
20
|
-
}
|
21
|
-
);
|
22
|
-
|
23
|
-
#[no_mangle]
|
24
|
-
pub extern fn initialize_me() {
|
25
|
-
Class::from_existing("String").define(|itself| {
|
26
|
-
itself.def("underscorify", underscorify);
|
27
|
-
itself.def("spacify", spacify);
|
28
|
-
});
|
29
|
-
}
|