Module: Nano::Check

Extended by:
Check
Included in:
Check
Defined in:
lib/nano/check.rb

Overview

The Check module contains some basic sanity and type checks to ensure robustness throughout the Gem.

Constant Summary collapse

MIN_INDEX =
0
MAX_INDEX =
2 ** 32 - 1

Instance Method Summary collapse

Instance Method Details

#is_balance_valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/nano/check.rb', line 37

def is_balance_valid?(value)
  value.match?(/^[0-9]*$/)
end

#is_hash_valid?(hash) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/nano/check.rb', line 53

def is_hash_valid?(hash)
  is_seed_valid?(hash)
end

#is_hex_valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/nano/check.rb', line 20

def is_hex_valid?(value)
  is_valid_hex?(value)
end

#is_index_valid?(index) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/nano/check.rb', line 45

def is_index_valid?(index)
  index.is_a?(Integer) && index >= MIN_INDEX && index <= MAX_INDEX
end

#is_key?(input) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/nano/check.rb', line 49

def is_key?(input)
  input.is_a?(String) && input.match?(/^[0-9a-fA-F]{64}$/)
end

#is_numerical?(value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nano/check.rb', line 24

def is_numerical?(value)
  return false unless value.is_a?(String)
  return false if value.start_with?(".")
  return false if value.end_with?(".")

  number_without_dot = value.sub(".", "")

  # More than one '.' in the number.
  return false unless number_without_dot.count(".") == 0

  is_balance_valid?(number_without_dot)
end

#is_seed_valid?(seed) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/nano/check.rb', line 41

def is_seed_valid?(seed)
  seed.is_a?(String) && seed.match?(/^[0-9a-fA-F]{64}$/)
end

#is_valid_account?(input) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/nano/check.rb', line 61

def is_valid_account?(input)
  !Nano::Account.from_address(input).nil?
end

#is_valid_hash?(value) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/nano/check.rb', line 16

def is_valid_hash?(value)
  is_hash_valid?(value)
end

#is_valid_hex?(value) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/nano/check.rb', line 12

def is_valid_hex?(value)
  value.is_a?(String) && value.match?(/^[0-9a-fA-F]{32}$/)
end

#is_work_valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/nano/check.rb', line 57

def is_work_valid?(input)
  input.is_a?(String) && input.match?(/^[0-9a-fA-F]{16}$/)
end