Sha256: eb6e8b9bf4035ace0fc068b7ed3c69d7bc84e89e783ea72653b6061de47ae59e

Contents?: true

Size: 647 Bytes

Versions: 1

Compression:

Stored size: 647 Bytes

Contents

# -*- encoding : utf-8 -*-

require 'sugar_utils/version'

module SugarUtils
  # @param [Object] value
  #
  # @return [Boolean]
  def self.ensure_boolean(value)
    return false if value.respond_to?(:to_s) && value.to_s.casecmp('false').zero?
    value ? true : false
  end

  # @param [String, Float, Integer] value
  #
  # @raise [ArgumentError] if the value is a string which cannot be converted
  # @raise [TypeError] if value is type which cannot be converted
  #
  # @return [Integer]
  def self.ensure_integer(value)
    return value      if value.is_a?(Integer)
    return value.to_i if value.is_a?(Float)
    Float(value).to_i
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sugar_utils-0.1.0 lib/sugar_utils.rb