tzispa_utils 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca4b92f6f0b683404de7f1cc52994ddf93999cf4
4
- data.tar.gz: 83300a6e5917346f27cda41d471ff7f4f1e719c6
3
+ metadata.gz: 84afafd3fd443191e29cfaaa958c1f78c83d292b
4
+ data.tar.gz: aad3274bc70c5260e89137f85b8e86703bfba7e8
5
5
  SHA512:
6
- metadata.gz: 2968a00cffa40a2afb2ac0b7155753b10eb1edc999afd1aacb6331b889cc5b1a6bda01a40064507688c32631fac820aec44e017fe37e7554b9340b0aff157886
7
- data.tar.gz: 830b03732abc7ceabca1dd9c3006e427015cd96cfd04422b28fa182e395fcf3d4ae45f5cae913351f8a6a25374231759c10491512db4fe72087d4ccadf15e6af
6
+ metadata.gz: 2c31286198ed0a482900d3d9d7627148873eb6dbeac75b8685fba44770a9665a5cb7864c725191d341b586232599a4dc42adb50e6bb9a2f04671c70182da9602
7
+ data.tar.gz: ebf06ff22e556514145b72097c80431fb20291be7dbce30d2ad1e8b4b1d22468950d5331fb42dd45c359c211a6b461626659aed1ff9e59ae99686f1d8f43a368
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Tzispa Utils
2
2
 
3
+ ## v0.3.3
4
+ - added new string refinement methods: to_bool, sanitize_filename
5
+ - optimizations in hash refinement symbolize methods
6
+
3
7
  ## v0.3.2
4
8
  - bug fixes
5
9
  - added tests for hash refinements
@@ -22,45 +22,49 @@ module Tzispa
22
22
 
23
23
  def symbolize!
24
24
  keys.each do |k|
25
- v = delete(k)
26
- self[k.to_sym] = v
25
+ self[k.to_sym] = delete(k) if k.respond_to? :to_sym
27
26
  end
28
27
 
29
28
  self
30
29
  end
31
30
 
32
- def deep_symbolize
33
- dup.tap do |hsh|
34
- hsh.keys.each do |k|
35
- v = hsh.delete(k)
36
- v = v.dup.deep_symbolize if v.respond_to?(:to_hash)
37
-
38
- hsh[k.to_sym] = v
39
- end
40
- end
41
- end
42
-
43
31
  def deep_symbolize!
44
32
  keys.each do |k|
45
- v = delete(k)
46
- v = v.deep_symbolize! if v.respond_to?(:to_hash)
47
-
48
- self[k.to_sym] = v
33
+ ks = k.respond_to?(:to_sym) ? k.to_sym : k
34
+ self[ks] = delete k # Preserve order even when k == ks
35
+ self[ks].deep_symbolize! if self[ks].is_a? ::Hash
49
36
  end
50
37
 
51
38
  self
52
39
  end
53
40
 
41
+ def deep_symbolize
42
+ dup.tap do |hs|
43
+ hs.keys.each do |k|
44
+ ks = k.respond_to?(:to_sym) ? k.to_sym : k
45
+ hs[ks] = hs.delete k # Preserve order even when k == ks
46
+ hs[ks] = hs[ks].deep_symbolize if hs[ks].is_a? ::Hash
47
+ end
48
+ end
49
+ end
50
+
54
51
  def stringify
55
52
  dup.tap(&:stringify!)
56
53
  end
57
54
 
58
55
  def stringify!
59
56
  keys.each do |k|
60
- v = delete(k)
61
- v = self.class.new(v).stringify! if v.respond_to?(:to_hash)
57
+ self[k.to_s] = delete(k) if k.respond_to? :to_s
58
+ end
62
59
 
63
- self[k.to_s] = v
60
+ self
61
+ end
62
+
63
+ def deep_stringify!
64
+ keys.each do |k|
65
+ ks = k.respond_to?(:to_s) ? k.to_s : k
66
+ self[ks] = delete k # Preserve order even when k == ks
67
+ self[ks].deep_symbolize! if self[ks].is_a? ::Hash
64
68
  end
65
69
 
66
70
  self
@@ -124,6 +124,10 @@ module Tzispa
124
124
  end
125
125
  alias_method :sanitize_htm, :sanitize_html
126
126
 
127
+ def sanitize_filename
128
+ gsub(%r{[\x00\/\\:\*\?\"\,\'<>\|]}, '')
129
+ end
130
+
127
131
  def escape_html
128
132
  EscapeUtils.escape_html(self)
129
133
  end
@@ -133,6 +137,13 @@ module Tzispa
133
137
  EscapeUtils.unescape_html(self)
134
138
  end
135
139
  alias_method :unescape_htm, :unescape_html
140
+
141
+ def to_bool
142
+ return true if self == true || self =~ /^(true|t|yes|y|1)$/i
143
+ return false if self == false || self =~ /^(false|f|no|n|0)$/i
144
+ raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
145
+ end
146
+ alias_method :to_boolean, :to_bool
136
147
  end
137
148
 
138
149
  refine String.singleton_class do
@@ -165,6 +176,10 @@ module Tzispa
165
176
  end
166
177
  alias_method :sanitize_htm, :sanitize_html
167
178
 
179
+ def sanitize_filename(str)
180
+ String.new(str).sanitize_filename
181
+ end
182
+
168
183
  def escape_html(str)
169
184
  String.new(str).escape_html
170
185
  end
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Utils
5
5
 
6
- VERSION = '0.3.2'
6
+ VERSION = '0.3.3'
7
7
  NAME = 'Tzispa Utils'
8
8
  GEM_NAME = 'tzispa_utils'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.6.10
132
+ rubygems_version: 2.6.11
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Utilities for Tzispa