string-utility 2.7.2 → 2.7.3

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: 6e462553b6a77784d686ffad8ffbfc7ccd9b1959
4
- data.tar.gz: 28208aab108398aefb3bbd5ac5c10fd05e144776
3
+ metadata.gz: 4a2b5e87c8eacc1c8298288a863648479d79a92b
4
+ data.tar.gz: ea2d2bfdfefea83ff19aaa28ff851ee037377e85
5
5
  SHA512:
6
- metadata.gz: 85f2d11d7b1428287c9a0ed6f15b58313d876bd152f29b261b02084325848f95aa6e682792eecf2d4653ca4a89e5e369d9afd4d32942fe2eb0ddab390253a6d3
7
- data.tar.gz: 119bd520fdac35064f8a5756016b42815680937bbca8c3f3a20dba34e0136c1a6a30bf8d58d823b1d6f425ca9d43c611b5dddc2719d160020fd3c37246d3cae4
6
+ metadata.gz: 6dad12d0aa07187cc0c682b1c9d6242dd89b1494dbf5eeaac50451563044cc4e300c0f7c44eeac2e8be0697e3adf1353f125a31dd2f874133dc86a0152ae90d7
7
+ data.tar.gz: f786694beb1eba79692b5b1676169d253504ee84dbbd128b1ddae01e738e03af19f7320f65336246e33b31cc3bb86115b62464fe3e606b09689f18fd378b968d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
  ## Version 2
3
+ ### Version 2.7.3
4
+ * 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.
5
+
3
6
  ### Version 2.7.2
4
7
  * No longer include tests in gem package.
5
8
  * License as MIT
data/ext/Cargo.toml ADDED
@@ -0,0 +1,16 @@
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 ADDED
@@ -0,0 +1,7 @@
1
+ all:
2
+ cargo build --release
3
+
4
+ clean:
5
+ rm -rf target
6
+
7
+ install: ;
data/ext/extconf.rb ADDED
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,29 @@
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
+ }
data/lib/utils.rb CHANGED
@@ -1,4 +1,9 @@
1
+ require 'fiddle'
2
+
3
+ LIBRARY = Fiddle.dlopen("#{File.dirname(__FILE__)}/../ext/target/release/libstringutility.dylib")
4
+
1
5
  module StringUtility
6
+ Fiddle::Function.new(LIBRARY['initialize_me'], [], Fiddle::TYPE_VOIDP).call
2
7
  refine String do
3
8
  # Separates the string by another string. Useful for converting integers
4
9
  # into human-readable numbers.
@@ -18,18 +23,6 @@ module StringUtility
18
23
  safely_gsub!(/\D/, '').to_i
19
24
  end
20
25
 
21
- # Replaces all whitespace with underscores.
22
- # @return [String] The string with replaced whitespace.
23
- def underscorify
24
- safely_gsub!(/\s/, '_')
25
- end
26
-
27
- # Replaces all underscores with whitespace.
28
- # @return [String] The string with replaced underscores.
29
- def spacify
30
- safely_gsub!('_', ' ')
31
- end
32
-
33
26
  # Readable shorthand for the only safe, fast way to use gsub! using || operators. Unlike gsub!, safely_gsub! will
34
27
  # NEVER return nil. This method should not be used instead of gsub! when the string replacement is predictable, as
35
28
  # this method is somewhat slower than gsub! (see spec/benchmark).
@@ -77,3 +70,14 @@ module StringUtility
77
70
  str
78
71
  end
79
72
  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,22 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-05-16 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: []
16
+ extensions:
17
+ - ext/extconf.rb
17
18
  extra_rdoc_files: []
18
19
  files:
19
20
  - CHANGELOG.md
21
+ - ext/Cargo.toml
22
+ - ext/Makefile
23
+ - ext/extconf.rb
24
+ - ext/src/lib.rs
20
25
  - lib/string-utility.rb
21
26
  - lib/utils.rb
22
27
  homepage: https://github.com/elifoster/string-utility-ruby