Class: Nanook::Key

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

Instance Method Summary collapse

Constructor Details

#initialize(rpc, key = nil) ⇒ Key

Returns a new instance of Key



4
5
6
7
# File 'lib/nanook/key.rb', line 4

def initialize(rpc, key=nil)
  @rpc = rpc
  @key = key
end

Instance Method Details

#generate(seed: nil, index: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/nanook/key.rb', line 9

def generate(seed: nil, index: nil)
  if seed.nil? && index.nil?
    rpc(:key_create)
  elsif !seed.nil? && !index.nil?
    rpc(:deterministic_key, seed: seed, index: index)
  else
    raise ArgumentError.new("This method must be called with either seed AND index params given or no params")
  end
end

#idObject



19
20
21
# File 'lib/nanook/key.rb', line 19

def id
  @key
end

#infoObject



23
24
25
26
# File 'lib/nanook/key.rb', line 23

def info
  key_required!
  rpc(:key_expand)
end

#inspectObject



28
29
30
# File 'lib/nanook/key.rb', line 28

def inspect
  "#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")"
end