Class: Realize::Format::Sha256

Inherits:
Object
  • Object
show all
Includes:
EncodingFormat
Defined in:
lib/realize/format/sha256.rb

Overview

Convert the value into a SHA256 encoded string. There are two main encoding formats: hex or base64. By default, the value will be hexidecimal encoded.

Defined Under Namespace

Modules: EncodingFormat

Constant Summary collapse

DEFAULT_ENCODING_FORMAT =
HEX

Constants included from EncodingFormat

EncodingFormat::BASE64, EncodingFormat::HEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoding_format: DEFAULT_ENCODING_FORMAT) ⇒ Sha256

Returns a new instance of Sha256.



27
28
29
30
31
# File 'lib/realize/format/sha256.rb', line 27

def initialize(encoding_format: DEFAULT_ENCODING_FORMAT)
  @encoding_format = EncodingFormat.const_get(encoding_format.to_s.upcase.to_sym)

  freeze
end

Instance Attribute Details

#encoding_formatObject (readonly)

Returns the value of attribute encoding_format.



25
26
27
# File 'lib/realize/format/sha256.rb', line 25

def encoding_format
  @encoding_format
end

Instance Method Details

#transform(_resolver, value, _time, _record) ⇒ Object



33
34
35
# File 'lib/realize/format/sha256.rb', line 33

def transform(_resolver, value, _time, _record)
  Digest::SHA256.send(sha_method, value.to_s)
end