Class: Webcash::Secret

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, secret_value) ⇒ Secret



10
11
12
13
14
# File 'lib/webcash/secret.rb', line 10

def initialize(amount, secret_value)
  Webcash::Helpers.validate_amount_decimals(amount)
  @amount = amount
  @secret_value = secret_value
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/webcash/secret.rb', line 7

def amount
  @amount
end

#secret_valueObject (readonly)

Returns the value of attribute secret_value.



8
9
10
# File 'lib/webcash/secret.rb', line 8

def secret_value
  @secret_value
end

Class Method Details

.deserialize(webcash) ⇒ Object



16
17
18
# File 'lib/webcash/secret.rb', line 16

def self.deserialize(webcash)
  Webcash::Helpers.deserialize_webcash(webcash)
end

.from_amount(amount) ⇒ Object



20
21
22
# File 'lib/webcash/secret.rb', line 20

def self.from_amount(amount)
  Webcash::Secret.deserialize(Webcash::Helpers.create_webcash_with_random_secret_from_amount(amount))
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/webcash/secret.rb', line 38

def ==(other)
  other.is_a?(Webcash::Secret) && @amount == other.amount && @secret_value == other.secret_value
end

#is_equal(other) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/webcash/secret.rb', line 24

def is_equal(other)
  if other.is_a?(Webcash::Secret)
    return true if @secret_value == other.secret_value
  elsif other.is_a?(Webcash::Public)
    return true if to_public.hashed_value == other.hashed_value
  end

  false
end

#to_publicObject



42
43
44
45
# File 'lib/webcash/secret.rb', line 42

def to_public
  hashed_value = Webcash::Helpers.convert_secret_value_to_public_value(@secret_value)
  Webcash::Public.new(@amount, hashed_value)
end

#to_sObject



34
35
36
# File 'lib/webcash/secret.rb', line 34

def to_s
  "e#{@amount.to_s('F').sub(/\.0+$/, '')}:secret:#{@secret_value}"
end