hash-utils 0.4.0 → 0.4.1
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.
- data/VERSION +1 -1
- data/hash-utils.gemspec +1 -1
- data/lib/hash-utils/string.rb +8 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/hash-utils.gemspec
CHANGED
data/lib/hash-utils/string.rb
CHANGED
@@ -70,33 +70,33 @@ class String
|
|
70
70
|
# @since 0.4.0
|
71
71
|
#
|
72
72
|
|
73
|
-
def
|
73
|
+
def strtr(defs, mode = nil, &block)
|
74
74
|
if block.nil?
|
75
75
|
block = Proc::new { |s| s }
|
76
76
|
end
|
77
77
|
|
78
|
-
defs, matcher =
|
78
|
+
defs, matcher = __prepare_strtr(defs, mode)
|
79
79
|
self.gsub(matcher) { |s| defs[block.call(s)] }
|
80
80
|
end
|
81
81
|
|
82
82
|
##
|
83
83
|
# Replaces set of substrings by another strings -- in place.
|
84
|
-
# See {#
|
84
|
+
# See {#strtr} for details.
|
85
85
|
#
|
86
86
|
# @param [Array, Hash] replacements replacements definition
|
87
87
|
# @param [Symbol] mode flat mode switch, can be +:flat+ or +nil+
|
88
88
|
# @param [Proc] block with keys mapping worker (see description)
|
89
89
|
# @return [String] string with applied replacements
|
90
|
-
# @see #
|
90
|
+
# @see #strtr
|
91
91
|
# @since 0.4.0
|
92
92
|
#
|
93
93
|
|
94
|
-
def
|
94
|
+
def strtr!(defs, mode = nil, &block)
|
95
95
|
if block.nil?
|
96
96
|
block = Proc::new { |s| s }
|
97
97
|
end
|
98
98
|
|
99
|
-
defs, matcher =
|
99
|
+
defs, matcher = __prepare_strtr(defs, mode)
|
100
100
|
self.gsub!(matcher) { |s| defs[block.call(s)] }
|
101
101
|
end
|
102
102
|
|
@@ -104,10 +104,10 @@ class String
|
|
104
104
|
private
|
105
105
|
|
106
106
|
##
|
107
|
-
# Prepares matcher for #
|
107
|
+
# Prepares matcher for #strtr.
|
108
108
|
#
|
109
109
|
|
110
|
-
def
|
110
|
+
def __prepare_strtr(defs, mode = nil)
|
111
111
|
defs = defs.to_h(mode)
|
112
112
|
keys = defs.keys
|
113
113
|
keys.map! { |i| i.to_s }
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Martin Koz\xC3\xA1k"
|
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
hash:
|
88
|
+
hash: 1545650960635711712
|
89
89
|
segments:
|
90
90
|
- 0
|
91
91
|
version: "0"
|