Sha256: d78b7563d7187f269fbdf8af04d2f2350c057d7c6998607f7e1bfe9f51215378

Contents?: true

Size: 676 Bytes

Versions: 12

Compression:

Stored size: 676 Bytes

Contents

# frozen_string_literal: true

module HoneyFormat
  # Converts decimal or nil
  ConvertDecimal = proc do |v|
    begin
      Float(v)
    rescue ArgumentError, TypeError
      nil
    end
  end

  # Converts to decimal or zero
  ConvertDecimalOrZero = proc { |v| v.to_f }

  # Convert to integer or nil
  ConvertInteger = proc do |v|
    begin
      Integer(v)
    rescue ArgumentError, TypeError
      nil
    end
  end

  # Convert to integer or zero
  ConvertIntegerOrZero = proc { |v| v.to_i }

  # Convert to decimal or raise error
  StrictConvertDecimal = proc { |v| Float(v) }

  # Convert to integer or raise error
  StrictConvertInteger = proc { |v| Integer(v) }
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
honey_format-0.27.0 lib/honey_format/converters/convert_number.rb
honey_format-0.26.0 lib/honey_format/converters/convert_number.rb
honey_format-0.25.0 lib/honey_format/converters/convert_number.rb
honey_format-0.24.0 lib/honey_format/converters/convert_number.rb
honey_format-0.23.0 lib/honey_format/converters/convert_number.rb
honey_format-0.22.0 lib/honey_format/converters/convert_number.rb
honey_format-0.21.1 lib/honey_format/converters/convert_number.rb
honey_format-0.21.0 lib/honey_format/converters/convert_number.rb
honey_format-0.20.0 lib/honey_format/converters/convert_number.rb
honey_format-0.19.0 lib/honey_format/converters/convert_number.rb
honey_format-0.18.0 lib/honey_format/converters/convert_number.rb
honey_format-0.17.0 lib/honey_format/converters/convert_number.rb