ostruct-sanitizer 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +3 -1
- data/lib/ostruct/sanitizer/version.rb +1 -1
- data/lib/ostruct/sanitizer.rb +10 -0
- 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: fb69d7d79fdbe87d7170925729d2322892251f0d
|
4
|
+
data.tar.gz: e7916d591ac8d1f636aaf594109ef95c0e7234c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d3a53a6bf8f18592ff87a1b284e61008418bfe0951afd59db0b434882427fbc14d8d9199518f76c77265cdaab4c2bf2055374d62f2343fa686e21d73d03b7b
|
7
|
+
data.tar.gz: 4dd3c31e4f72e2af30218071fc24b37847e4d9a6156adebdbb133250e28a87ee0a32bbda852a4ec636041a0dbea8461cef991e0b2a2c0b3f30fa10c5905ac52e
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# OStruct::Sanitizer
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/powerhome/ostruct-sanitizer)
|
4
|
+
|
5
|
+
Provides Rails-like sanitization hooks to be applied to OpenStruct fields upon their assignment, allowing for better encapsulation of such rules and simple extensibility.
|
4
6
|
|
5
7
|
This module provides a few built-in sanitization rules, all built upon the basic `#sanitize` method used as building block.
|
6
8
|
|
data/lib/ostruct/sanitizer.rb
CHANGED
@@ -110,6 +110,16 @@ module OStruct
|
|
110
110
|
sanitize(field) { |value| value.strip }
|
111
111
|
end
|
112
112
|
end
|
113
|
+
|
114
|
+
# Removes any non-digit character from the values of the given fields
|
115
|
+
#
|
116
|
+
# @param [Array<Symbol>] fields list of fields to be sanitized
|
117
|
+
#
|
118
|
+
def digits(*fields)
|
119
|
+
fields.each do |field|
|
120
|
+
sanitize(field) { |value| value.to_s.gsub(/[^0-9]/, '') }
|
121
|
+
end
|
122
|
+
end
|
113
123
|
end
|
114
124
|
end
|
115
125
|
end
|