Sha256: f4c22be397b44fe5aa6f6e7ed4c733e1c9f056efbe09a1a819245162d89ba4f3

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Workato
  module Extension
    module Object
      # rubocop:disable Naming/PredicateName
      def is_true?(null_true: false)
        if is_a?(::String)
          return true if (self =~ (/\A(true|t|yes|y|1)\Z/i)).present?
          return false if (self =~ (/\A(false|f|no|n|0)\Z/i)).present?
          raise "Can't convert empty string to boolean" if blank?

          raise "Can't convert string value #{self} to boolean"
        elsif is_a?(::Integer)
          return true if self == 1
          return false if zero?

          raise "Can't convert number value #{self} to boolean"
        elsif is_a?(::TrueClass)
          true
        elsif is_a?(::FalseClass)
          false
        elsif is_a?(::NilClass)
          null_true == true
        else
          raise "Can't convert type #{self.class.name} to boolean"
        end
      end

      def is_not_true?(null_not_true: true)
        !is_true?(null_true: !null_not_true)
      end
      # rubocop:enable Naming/PredicateName
    end
  end
end

Object.include(Workato::Extension::Object)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
workato-connector-sdk-1.0.1 lib/workato/extension/object.rb
workato-connector-sdk-1.0.0 lib/workato/extension/object.rb
workato-connector-sdk-0.5.0 lib/workato/extension/object.rb
workato-connector-sdk-0.4.1 lib/workato/extension/object.rb
workato-connector-sdk-0.4.0 lib/workato/extension/object.rb
workato-connector-sdk-0.3.0 lib/workato/extension/object.rb
workato-connector-sdk-0.2.0 lib/workato/extension/object.rb
workato-connector-sdk-0.1.2 lib/workato/extension/object.rb
workato-connector-sdk-0.1.1 lib/workato/extension/object.rb
workato-connector-sdk-0.1.0 lib/workato/extension/object.rb