Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/monkey_patches.rb,
lib/monkey_patches.rb
Overview
check if is a checksum
Constant Summary collapse
- REGEX =
/\A[0-9a-f]{32,128}\z/i
- CHARS =
{ md2: 32, md4: 32, md5: 32, sha1: 40, sha224: 56, sha256: 64, sha384: 96, sha512: 128 }
Instance Method Summary collapse
-
#be_a_checksum ⇒ Object
return if this a checksum.
-
#deep_string_keys ⇒ Object
transform hash keys to strings.
-
#deep_symbolize_keys ⇒ Object
transform hash keys to symbols.
-
#produced_by(name) ⇒ Object
return true if the checksum created by spezified type.
Instance Method Details
#be_a_checksum ⇒ Object
return if this a checksum
80 81 82 |
# File 'lib/monkey_patches.rb', line 80 def be_a_checksum !!(self =~ REGEX) end |
#deep_string_keys ⇒ Object
transform hash keys to strings
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/monkey_patches.rb', line 43 def deep_string_keys if( is_a?( Hash ) ) return inject({}) do |memo, (k, v)| memo.tap { |m| m[k.to_s] = v.deep_string_keys } end elsif( is_a?( Array ) ) return map(&:deep_string_keys) end self end |
#deep_symbolize_keys ⇒ Object
transform hash keys to symbols
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/monkey_patches.rb', line 28 def deep_symbolize_keys if( is_a?( Hash ) ) return inject({}) do |memo, (k, v)| memo.tap { |m| m[k.to_sym] = v.deep_string_keys } end elsif( is_a?( Array ) ) return map(&:deep_string_keys) end self end |
#produced_by(name) ⇒ Object
return true if the checksum created by spezified type
92 93 94 95 96 97 98 99 |
# File 'lib/monkey_patches.rb', line 92 def produced_by( name ) function = name.to_s.downcase.to_sym raise ArgumentError, "unknown algorithm given to be_a_checksum.produced_by: #{function}" unless CHARS.include?(function) return true if( size == CHARS[function] ) false end |