Sha256: 732b3fb308a99e3d387a92aebe00f01169469beb638c97074835d35f98cd65a1

Contents?: true

Size: 650 Bytes

Versions: 124

Compression:

Stored size: 650 Bytes

Contents

# frozen_string_literal: true

module EacRubyUtils
  class Boolean
    class << self
      def parse(value)
        return parse_string(value) if value.is_a?(::String)
        return parse_string(value.to_s) if value.is_a?(::Symbol)
        return parse_number(value) if value.is_a?(::Number)

        value ? true : false
      end

      private

      def parse_string(value)
        ['', 'n', 'no', 'f', 'false'].include?(value.strip.downcase) ? false : true
      end

      def parse_number(value)
        value.zero?
      end
    end

    attr_reader :value

    def initialize(value)
      @value = self.class.parse(value)
    end
  end
end

Version data entries

124 entries across 124 versions & 3 rubygems

Version Path
ehbrs-tools-0.23.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.69.0 lib/eac_ruby_utils/boolean.rb
avm-tools-0.103.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
ehbrs-tools-0.22.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.102.2 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.102.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.68.0 lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.67.0 lib/eac_ruby_utils/boolean.rb
avm-tools-0.102.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.66.0 lib/eac_ruby_utils/boolean.rb
avm-tools-0.101.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.65.0 lib/eac_ruby_utils/boolean.rb
avm-tools-0.100.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
ehbrs-tools-0.21.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.99.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.64.0 lib/eac_ruby_utils/boolean.rb
avm-tools-0.99.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.98.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.97.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
avm-tools-0.96.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb