Class: Zold::Wallets
- Inherits:
-
Object
- Object
- Zold::Wallets
- Defined in:
- lib/zold/wallets.rb
Overview
Collection of local wallets
Instance Method Summary collapse
-
#all ⇒ Object
Returns the list of their IDs (as plain text).
- #find(id) ⇒ Object
-
#initialize(dir) ⇒ Wallets
constructor
A new instance of Wallets.
- #path ⇒ Object
- #to_s ⇒ Object
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
#all ⇒ Object
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 |
#path ⇒ Object
42 43 44 45 |
# File 'lib/zold/wallets.rb', line 42 def path FileUtils.mkdir_p(@dir) File.(@dir) end |
#to_s ⇒ Object
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 |