Sha256: 29e35f2615607cf89c3b93dc36652a7d4331f4d5eee5e56cd81a42b608f61ade

Contents?: true

Size: 389 Bytes

Versions: 4

Compression:

Stored size: 389 Bytes

Contents

module Swagger
  class Boolean
    TRUE_REGEXP = /(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)/
    FALSE_REGEXP = /(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)/

    def self.coerce(obj)
      val = obj.to_s.downcase
      return true if val.match(TRUE_REGEXP)
      return false if val.match(FALSE_REGEXP)
      fail ArgumentError, "#{obj} cannot be coerced to a boolean"
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
swagger-parser-0.2.6 lib/swagger/boolean.rb
swagger-parser-0.2.5 lib/swagger/boolean.rb
swagger-core-0.2.3 lib/swagger/boolean.rb
swagger-core-0.2.2 lib/swagger/boolean.rb