Completed
Push — master ( c24669...17b1aa )
by Marcelo
37s
created

String.coerce()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
1
module Koine
2
  module Attributes
3
    module Adapter
4
      class String < Base
5
        def empty_to_nil
6
          with_nil_value(nil)
7
          @empty_to_nil = true
8
          self
9
        end
10
11
        def trim_empty_spaces
12
          @trim_empty_spaces = true
13
          self
14
        end
15
16
        private
17
18
        def coerce_not_nil(value)
19
          secure do
20
            value = String(value)
21
            value = value.strip if @trim_empty_spaces
22
            return nil if value.empty? && @empty_to_nil
23
            value
24
          end
25
        end
26
      end
27
    end
28
  end
29
end
30