Sha256: e085599ebb5b6c15470038a0282b00470e6f39767c01ce0b44d778c969022569

Contents?: true

Size: 573 Bytes

Versions: 10

Compression:

Stored size: 573 Bytes

Contents

module Koine
  module Attributes
    module Adapter
      class String < Base
        def empty_to_nil
          with_nil_value(nil)
          @empty_to_nil = true
          self
        end

        def trim_empty_spaces
          @trim_empty_spaces = true
          self
        end

        private

        def coerce_not_nil(value)
          secure do
            value = String(value)
            value = value.strip if @trim_empty_spaces
            return nil if value.empty? && @empty_to_nil
            value
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
koine-attributes-1.2.3 lib/koine/attributes/adapter/string.rb
koine-attributes-1.2.2 lib/koine/attributes/adapter/string.rb
koine-attributes-1.2.1 lib/koine/attributes/adapter/string.rb
koine-attributes-1.2.0 lib/koine/attributes/adapter/string.rb
koine-attributes-1.1.0 lib/koine/attributes/adapter/string.rb
koine-attributes-1.0.0 lib/koine/attributes/adapter/string.rb
koine-attributes-0.4.0 lib/koine/attributes/adapter/string.rb
koine-attributes-0.3.2 lib/koine/attributes/adapter/string.rb
koine-attributes-0.3.1 lib/koine/attributes/adapter/string.rb
koine-attributes-0.3.0 lib/koine/attributes/adapter/string.rb