Sha256: 7665a254a143192df418dd7e8a9ee901e4a47672a73f3596e745fc133b9aa0c2

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 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 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 symbol or raise error
  StrictConvertSymbol = proc do |v|
    ConvertSymbol.call(v) || raise(ArgumentError, "can't convert nil to symbol")
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
honey_format-0.23.0 lib/honey_format/converters/convert_string.rb
honey_format-0.22.0 lib/honey_format/converters/convert_string.rb
honey_format-0.21.1 lib/honey_format/converters/convert_string.rb
honey_format-0.21.0 lib/honey_format/converters/convert_string.rb
honey_format-0.20.0 lib/honey_format/converters/convert_string.rb
honey_format-0.19.0 lib/honey_format/converters/convert_string.rb
honey_format-0.18.0 lib/honey_format/converters/convert_string.rb
honey_format-0.17.0 lib/honey_format/converters/convert_string.rb