Module: RecordOnChain::Utils

Defined in:
lib/record_on_chain/utils.rb

Class Method Summary collapse

Class Method Details

.bytes_to_hex(bytes) ⇒ Object



14
15
16
# File 'lib/record_on_chain/utils.rb', line 14

def bytes_to_hex( bytes )
  return bytes.unpack("H*").first
end

.hex_str?(str, byte_size = -1 )) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/record_on_chain/utils.rb', line 27

def hex_str?( str , byte_size= -1 )
  str_size = str.size
  return false if str_size.odd?
  except_prefix = str.start_with?("0x") ? str[ 1 , str_size-2 ] : str
  # validate size ( byte_size <= 0 ---> ignore )
  return false if byte_size > 0 && str_size != byte_size*2
  not_hex = /[^\dabcdef]/
  return !not_hex.match?( except_prefix )
end

.hex_to_bytes(hex) ⇒ Object



18
19
20
# File 'lib/record_on_chain/utils.rb', line 18

def hex_to_bytes( hex )
  return [hex].pack("H*")
end

.symbolize_hashkeys_rf(hash_data) ⇒ Object

reflexivity symbolize hash keys



5
6
7
8
9
10
11
12
# File 'lib/record_on_chain/utils.rb', line 5

def symbolize_hashkeys_rf( hash_data )
  result = {}
  hash_data.each do |key,value|
    value = symbolize_hashkeys_rf( value ) if value.class.equal?( {}.class )
    result[ key.to_sym ] = value
  end
  return result
end

.validate_password(passwd) ⇒ Object



22
23
24
25
# File 'lib/record_on_chain/utils.rb', line 22

def validate_password( passwd )
  pattern = /[^\w#\$%&@\/?\.+]/
  (pattern =~ passwd).nil? ? true : false
end