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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dcd0548a4279bf377323dde2be51918489d4c45
4
- data.tar.gz: 8d600d0868fdb8cd369792f7c87f2eb6608aa87a
3
+ metadata.gz: 6da140fccc56d959e8a81f0635b28a2b58e66aec
4
+ data.tar.gz: 117e2dd751d2b26f7555eaf4fcfb455f5129634f
5
5
  SHA512:
6
- metadata.gz: 8cd07dca6d185b9519d0a289c74bd20dd4b1b163e09c5d32903eed2a927f4957d52876db63f87fb02eb8cf53d08061c63b7f748735d1c974d8a6e1d25430425b
7
- data.tar.gz: b571487b251e3744ddc76cc024204369a6ac575ba73abeb78dddd98022dd02957a260adf6e5e0f0b039a14c1a4a7dab81867c4add1f18491e3f7088ae380b2a5
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
- :symbol
185
- :time
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
@@ -1,5 +1,5 @@
1
1
  module Koine
2
2
  module Attributes
3
- VERSION = '0.2.2'.freeze
3
+ VERSION = '0.2.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koine-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus