koine-attributes 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -10
- data/lib/koine/attributes/adapter/string.rb +14 -1
- data/lib/koine/attributes/version.rb +1 -1
- 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: 6da140fccc56d959e8a81f0635b28a2b58e66aec
|
4
|
+
data.tar.gz: 117e2dd751d2b26f7555eaf4fcfb455f5129634f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4064ef3599fbf212fefd43db605a59dc717219750f2d1c39bd806b7770cc7d9a11fe2e066517e4c1dd980a24b6da9aeff5406ad0fdae8b84167967d020ba72e
|
7
|
+
data.tar.gz: f887ffe331009e118d15a719d703178d893eba01334284bdfede204760a1b9c0d2407f866f5031d3dcf7317779f1e91d6e44f47557b5b1e574e8748cc2061f5e
|
data/README.md
CHANGED
@@ -173,16 +173,18 @@ new_location = location.with_lon(3)
|
|
173
173
|
### Standard types
|
174
174
|
|
175
175
|
```ruby
|
176
|
-
:any
|
177
|
-
:array_of
|
178
|
-
:boolean
|
179
|
-
:date
|
180
|
-
:float
|
181
|
-
:hash_of
|
182
|
-
:integer
|
183
|
-
:string
|
184
|
-
|
185
|
-
|
176
|
+
- :any
|
177
|
+
- :array_of
|
178
|
+
- :boolean
|
179
|
+
- :date
|
180
|
+
- :float
|
181
|
+
- :hash_of
|
182
|
+
- :integer
|
183
|
+
- :string
|
184
|
+
- empty_to_nil
|
185
|
+
- trim_empty_spaces
|
186
|
+
- :symbol
|
187
|
+
- :time
|
186
188
|
```
|
187
189
|
|
188
190
|
### Alternative solutions
|
@@ -2,9 +2,22 @@ module Koine
|
|
2
2
|
module Attributes
|
3
3
|
module Adapter
|
4
4
|
class String < Base
|
5
|
+
def empty_to_nil
|
6
|
+
@empty_to_nil = true
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def trim_empty_spaces
|
11
|
+
@trim_empty_spaces = true
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
5
15
|
def coerce(value)
|
6
16
|
secure do
|
7
|
-
String(value)
|
17
|
+
value = String(value)
|
18
|
+
value = value.strip if @trim_empty_spaces
|
19
|
+
return nil if value.empty? && @empty_to_nil
|
20
|
+
value
|
8
21
|
end
|
9
22
|
end
|
10
23
|
end
|