Completed
Push — master ( a85492...c24669 )
by Marcelo
32s
created

String.trim_empty_spaces()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
1
module Koine
2
  module Attributes
3
    module Adapter
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
15
        def coerce(value)
16
          secure do
17
            value = String(value)
18
            value = value.strip if @trim_empty_spaces
19
            return nil if value.empty? && @empty_to_nil
20
            value
21
          end
22
        end
23
      end
24
    end
25
  end
26
end
27