Sha256: f80d7842cf6514de76b449ec2b701dc6fca5d7c7705bc6fa3acdc97cca0a59f2

Contents?: true

Size: 605 Bytes

Versions: 2

Compression:

Stored size: 605 Bytes

Contents

module NsOptions
  class Boolean

    attr_accessor :actual

    def initialize(value)
      self.actual = value
    end

    def actual=(new_value)
      @actual = self.convert(new_value)
    end

    def ==(other_boolean)
      if other_boolean.kind_of?(Boolean)
        self.actual == other_boolean.actual
      else
        self.actual == other_boolean
      end
    end

    def returned_value
      self.actual
    end

    protected

    def convert(value)
      if [ nil, 0, '0', false, 'false', 'f', 'F' ].include?(value)
        false
      elsif value
        true
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ns-options-0.4.1 lib/ns-options/boolean.rb
ns-options-0.4.0 lib/ns-options/boolean.rb