Class: Zold::Wallets

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

Overview

Collection of local wallets

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Wallets

Returns a new instance of Wallets.


31
32
33
# File 'lib/zold/wallets.rb', line 31

def initialize(dir)
  @dir = dir
end

Instance Method Details

#allObject

Returns the list of their IDs (as plain text)


48
49
50
51
52
53
54
55
56
# File 'lib/zold/wallets.rb', line 48

def all
  Dir.new(path).select do |f|
    file = File.join(@dir, f)
    File.file?(file) &&
      !File.directory?(file) &&
      f =~ /^[0-9a-fA-F]{16}$/ &&
      Id.new(f).to_s == f
  end
end

#find(id) ⇒ Object


58
59
60
61
62
# File 'lib/zold/wallets.rb', line 58

def find(id)
  raise 'Id can\'t be nil' if id.nil?
  raise 'Id must be of type Id' unless id.is_a?(Id)
  Zold::Wallet.new(File.join(path, id.to_s))
end

#pathObject


42
43
44
45
# File 'lib/zold/wallets.rb', line 42

def path
  FileUtils.mkdir_p(@dir)
  File.expand_path(@dir)
end

#to_sObject

TODO:

#70:30min Let's make it smarter. Instead of returning the full path let's substract the prefix from it if it's equal to the current directory in Dir.pwd.


38
39
40
# File 'lib/zold/wallets.rb', line 38

def to_s
  path
end