Sha256: 109409e20fbaaffdcbd059563b5ae233aa22d9b3f7c60c01441397f6e9c70fd3

Contents?: true

Size: 755 Bytes

Versions: 26

Compression:

Stored size: 755 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Boolean
      module Casters
        class StringOrSymbol < Value::Caster
          TRUE_VALUES =  Set["true", "t", "1", "yes", "y"]
          FALSE_VALUES = Set["false", "f", "0", "no", "n"]
          ALLOWED_VALUES = TRUE_VALUES | FALSE_VALUES

          def applicable?(value)
            value = value.to_s if value.is_a?(::Symbol)

            value.is_a?(::String) && ALLOWED_VALUES.include?(value.downcase)
          end

          def applies_message
            "be a String or Symbol that is one of #{ALLOWED_VALUES.join(", ")} (case-insensitive)"
          end

          def cast(value)
            TRUE_VALUES.include?(value.to_s.downcase)
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.25 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.24 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.23 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.22 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.21 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.20 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.19 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.18 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.17 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.16 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.15 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.14 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.13 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.12 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.11 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.10 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.9 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.8 projects/builtin_types/src/boolean/casters/string_or_symbol.rb
foobara-0.0.7 projects/builtin_types/src/boolean/casters/string_or_symbol.rb