Sha256: 7371bee54e7590704f7bf2ad777c0c8df59ff140bbc149efd718715f7c71a4e9

Contents?: true

Size: 651 Bytes

Versions: 219

Compression:

Stored size: 651 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?(::Numeric)

        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

219 entries across 219 versions & 4 rubygems

Version Path
eac_tools-0.41.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.40.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.39.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.106.1 lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.106.0 lib/eac_ruby_utils/boolean.rb
eac_tools-0.38.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.37.2 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.105.0 lib/eac_ruby_utils/boolean.rb
eac_tools-0.37.1 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.37.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.36.1 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.36.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.35.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.34.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.33.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.32.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_ruby_utils-0.104.0 lib/eac_ruby_utils/boolean.rb
eac_tools-0.31.1 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.31.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
eac_tools-0.30.0 sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb