stringer-rss/stringer

View on GitHub
app/commands/cast_boolean.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module CastBoolean
  TRUE_VALUES = Set.new(["true", true, "1"]).freeze
  FALSE_VALUES = Set.new(["false", false, "0"]).freeze

  def self.call(boolean)
    if (TRUE_VALUES + FALSE_VALUES).exclude?(boolean)
      raise(ArgumentError, "cannot cast to boolean: #{boolean.inspect}")
    end

    TRUE_VALUES.include?(boolean)
  end
end