Sha256: 5b16617f5e749c8d04d55f2ac0458270d902eb9d711617f9bdc5aa2b1bab58f2

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'digest'
require 'securerandom'

module HoneyFormat
  # Convert to downcase or nil
  ConvertDowncase = proc { |v| v&.downcase }

  # Convert to upcase or nil
  ConvertUpcase = proc { |v| v&.upcase }

  # Convert to stripped string
  ConvertStrip = proc { |v| v&.strip }

  # Convert to symbol or nil
  ConvertSymbol = proc { |v| v&.to_sym }

  # Convert to md5 or nil
  ConvertMD5 = proc { |v| Digest::MD5.hexdigest(v) if v }

  # Convert to hex or nil
  ConvertHex = proc { |v| SecureRandom.hex if v }

  # Convert to blank string
  ConvertBlank = proc { '' }

  # Convert header column
  ConvertHeaderColumn = HeaderColumnConverter

  # Convert to upcase or raise error
  StrictConvertUpcase = proc do |v|
    ConvertUpcase.call(v) || raise(ArgumentError, "can't convert nil to upcased string")
  end

  # Convert to downcase or raise error
  StrictConvertDowncase = proc do |v|
    ConvertDowncase.call(v) || raise(ArgumentError, "can't convert nil to downcased string")
  end

  # Convert to downcase or raise error
  StrictConvertStrip = proc do |v|
    ConvertStrip.call(v) || raise(ArgumentError, "can't convert nil to downcased string")
  end

  # Convert to symbol or raise error
  StrictConvertSymbol = proc do |v|
    ConvertSymbol.call(v) || raise(ArgumentError, "can't convert nil to stripped string")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
honey_format-0.27.0 lib/honey_format/converters/convert_string.rb
honey_format-0.26.0 lib/honey_format/converters/convert_string.rb
honey_format-0.25.0 lib/honey_format/converters/convert_string.rb
honey_format-0.24.0 lib/honey_format/converters/convert_string.rb