Sha256: 94b70bdefedb32b8f60aef75dc00587b003004d04a8686e615989f9536dc84e0

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Hari
  class Entity
    module Serialization
      module Boolean

        MAPPINGS  = {
          true    => true,
          'true'  => true,
          'TRUE'  => true,
          '1'     => true,
          1       => true,
          1.0     => true,
          'x'     => true,
          'X'     => true,
          't'     => true,
          'T'     => true,
          false   => false,
          'false' => false,
          'FALSE' => false,
          '0'     => false,
          0       => false,
          0.0     => false,
          ''      => false,
          ' '     => false,
          'f'     => false,
          'F'     => false,
          nil     => false
        }.freeze

        def self.serialize(value, options = {})
          desserialize value, options
        end

        def self.desserialize(value, options = {})
          MAPPINGS[value].tap do |bool|
            fail SerializationError, "#{options[:name]}:#{value} is not boolean" if bool.nil?
          end
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hari-0.0.5 lib/hari/entity/serialization/boolean.rb
hari-0.0.4 lib/hari/entity/serialization/boolean.rb
hari-0.0.3 lib/hari/entity/serialization/boolean.rb
hari-0.0.1 lib/hari/entity/serialization/boolean.rb