Class: Sha256Seal::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/sha256_seal.rb

Overview

Main class for the Sha256Seal library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, secret, field) ⇒ Builder

Returns a new instance of Builder.

Raises:

  • (::ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sha256_seal.rb', line 11

def initialize(value, secret, field)
  @value  = value.to_s
  @secret = secret.to_s
  @field  = field.to_s

  i = @value.scan(@field).length

  return if i.equal?(1)

  raise ::ArgumentError, "#{i} #{@field.inspect} occurrences instead of 1."
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



9
10
11
# File 'lib/sha256_seal.rb', line 9

def field
  @field
end

#secretObject (readonly)

Returns the value of attribute secret.



9
10
11
# File 'lib/sha256_seal.rb', line 9

def secret
  @secret
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/sha256_seal.rb', line 9

def value
  @value
end

Instance Method Details

#signed_valueObject



23
24
25
# File 'lib/sha256_seal.rb', line 23

def signed_value
  value.gsub(field, signature)
end

#signed_value?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sha256_seal.rb', line 27

def signed_value?
  signature.eql?(field)
end